H
hurcan solter
Consider the code fragment;
class A
{
public:
A(){}
A(int prm):mprm(prm){}
int mprm;
};
class B
ublic A
{
public:
B(){}
B(int prm):A(prm){}
};
class C
ublic B//,public virtual A
public:
c(){}
C(int prm):A(prm){}
};
int main()
{
C c(3);
}
well my compiler says that 'A' is not a base class of 'C' so i assume
you can only initialize
your immediate base class(why?),but if i remove the comment and
virtually inherit from 'A' the code runs ok, but i feel like i am
creating two A objects (default A constructor called) which is not the
intended behavior, is that true?Does virtual inheritance guarantee only
one 'A' is created?
class A
{
public:
A(){}
A(int prm):mprm(prm){}
int mprm;
};
class B
{
public:
B(){}
B(int prm):A(prm){}
};
class C
public:
c(){}
C(int prm):A(prm){}
};
int main()
{
C c(3);
}
well my compiler says that 'A' is not a base class of 'C' so i assume
you can only initialize
your immediate base class(why?),but if i remove the comment and
virtually inherit from 'A' the code runs ok, but i feel like i am
creating two A objects (default A constructor called) which is not the
intended behavior, is that true?Does virtual inheritance guarantee only
one 'A' is created?