I am trying to create a base template class, the parameter T must be a structure.
When I use a variable declared as type T (both in the template class and in the class that extends it by defining T ), GCC cannot compile it:
GCC error: Invalid use of incomplete type 'struct x'
Despite the fact that it works on VC, I understand that it does not work, because it should not, because the compiler does not know in the standard the types that T represent.
Is there a way to make explicit that a type should be a structure?
What I do in the code that works in VC is:
In the base class:
T* x
new T
sizeof(T)
In those that expand it:
x->member
: . :
struct SomeStructureType
{
int memberA;
int memberB;
}
template <typename T> class Base
{
protected:
T* s;
void addMember(string name,void* offset);
Base()
{
s = new T;
}
};
class Extender : public Base<SomeStructureType>
{
public:
Extender()
{
addMember("memberA",&s->memberA);
}
}