Hi Everybody,
I have 3 classes, A, B and C.
1 2 3 4 5 6 7 8 9 10 11 12
|
class A {
private:
int N;
public:
int *VectorInA; // Size N
void SetN_A(int n){ N = n; } // This is used by the constructor of
// the derived class described above.
(... everything else ...)
};
|
The other classes look more or less the same.
After, I construct 3 derived classes AB, AC and BC. These contain no data, but functions relating the Vectors In A B and C.
1 2 3 4 5
|
class AB: public A, public B{
(... stuff ...)
};
|
The size of the vectors N, is the same for all classes.
I have 3 questions.
1:
If I write
static int N
instead of
int N
, I get the error message
the same number of times I try to use this static variable.
Why?
(I don't mind just int, but I want to know why.)
2:
If I don't include a variable N in the classes AB etc, the compiler says that there are ambiguities when this variable is called. I really don't want to name each one NA NB and NC in the classes A B and C but there has to be a better way to deal with this problem rather than introducing yet more variables N (one in each class AB, AC and BC) whose value will be the same.
3:
In the constructors of the classes AB AC and BC, I write:
If I don't, I get errors
etc. However, if I write
|
delete [] VectorInA; delete [] VectorInB;
|
in the destructor of the classes AB etc. I get
double free or corruption (fasttop) |
etc.
This makes me thing that the destructor of the classes A and B are called in the destructor of the derived classes, but NOT the constructor. (However, my bibliography states the opposite.)
I just want to make sure that I don't have a memory leak. Suggestions?
By the way, I use g++.
Thanks !!