You must create a base class that will have 4 heirs. The problem is that I need a base class in one instance, since there will be stored pointers to inherited objects + there are inherited classes that will not be created immediately and I need to determine which ones will be created and which ones will not be in the array.
The question is: There is a code:
header class dataBase { public: std::vector<dataBase*> data; dataBase(); int a=0; static int sl; }; class type1 : public virtual dataBase { public: type1(); int b; }; class type2: public virtual dataBase { public: type2(); int c; }; where in the implementation for each:
int dataBase::sl=0; dataBase::dataBase() { sl++; a=sl; } type1::type1(){ data.insert(data.end(), this); b=a; } type2::type2() { data.insert(data.end(), this); c=a; } The problem is that by defining a class heir to a virtual one, as I understand it, it makes it possible not to create a copy of the base class, it still creates a copy. If you look at the counter of a static variable, it will indicate that the base class was created two times.
And if you write to variable a from the inherited class type1, then in type2 you get another number (random, if you discard the constructor code.)
Please help me figure it out. Thanks in advance.