The template parameter parameter must be a structure

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);
        }
}
+3
4

( ) "" , , .

, : , , ... , : , , - ...

+1

; ++ , .

. -, struct x, x. , . , StackOverflow - .

+1
+1

The problem is not related to the fact that T must be a structure. The problem is that one of the structures (which I use in my code but was not created by me) is said to be incomplete gcc. Anyway, I deleted the class that uses this structure, and other classes are compiled with the same base class. So it is up to me to fix this, and what I suspected about the problem was wrong.

0
source

Source: https://habr.com/ru/post/1728924/


All Articles