B<10> b;
size_t *arr = reinterpret_cast<size_t *>(&b);
for (size_t i = 0; i < 10; i++)
arr[i]=12345;
#include <iostream>
template <size_t size>
class B {
const size_t data[size];
};
template<size_t size>
class A
{
A<size-1> agg;
B<size> items[size];
public:
};
template<>
class A<1>
{
B<1> items[1];
};
int main()
{
std::cout << sizeof(A<10>) << std::endl;
}
#include <iostream>
#include <stack>
struct IElement
{
virtual ~IElement() {}
};
struct ElementInt: IElement
{
int value = 0;
ElementInt(int v):value(v){}
};
struct ElementFloat: IElement
{
float value;
ElementFloat(int v):value(v){}
};
struct ElementFactory
{
public:
ElementFactory(){}
virtual ~ElementFactory(){}
IElement* createInt(int value) const
{
return new ElementInt(value);
}
IElement* createFloat(float value) const
{
return new ElementInt(value);
}
};
struct Stack
{
public:
Stack(size_t s)
: _size(0)
, _stack(new IElement*[s])
{}
virtual ~Stack()
{
delete[] _stack;
}
IElement* pop()
{
if ( _size==0 )
return nullptr;
return _stack[--_size];
}
void push(IElement* elem)
{
_stack[_size++]=elem;
}
private:
size_t _size;
IElement** _stack;
};
int main()
{
ElementFactory f;
Stack s(3);
s.push( f.createInt(10) );
s.push( f.createFloat(20.0) );
s.push( f.createFloat(30) );
while ( IElement* pval = s.pop() )
{
if ( ElementInt* vint = dynamic_cast<ElementInt*>(pval))
std::cout << vint->value << std::endl;
else if ( ElementFloat* vint =dynamic_cast<ElementFloat*>(pval))
std::cout << vint->value << std::endl;
delete pval;
}
return 0;
}
// на самом деле копия
auto ref = myClass->summ(10).retract(4);