
Subclassed copy constructor not working
Hello,
I'd really appreciate it if someone could give me a (hopefully) quick
answer to this little conundrum:
I've got a class
class A
{
public:
A(A* pA);
A();
virtual ~A();
Quote:
}
A::A()
{
Quote:
}
A::A(A* pA)
{
if(pA)
{
//variable copying here
}
Quote:
}
And another class
class B : public A
{
public:
B(B* pB);
B();
virtual ~B();
Quote:
}
B::B()
{
Quote:
}
B::B(B* pB)
{
if(pB)
{
//variable copying here
//but I also want to copy all of the base class
variables, so
A((A*)pB); <--- PROBLEM
}
Quote:
}
So if I want to make a copy of my class B
B* pX=new B();
B* pB=new B(pX);
All the variables in B are copied OK, but the base class variables
aren't. It seems to make a new class of type A and then delete it
immediately.
Question - What syntax do I need to succesfully copy B with all the
base class variables in A?
Regards,
Si