I have a small question:
I have these classes:
Now I want to instantiate class B, and I do it like this:
This doesn't work. Why not? Shouldn't class B automatically use the ctor of A when it's not available in the same form in class B, just like any other method?
Right now, I fixed it like this:
This doesn't work either; the compiler complains about a missing default ctor. So I added one to class A:
Now it compiles. But does this work like I expect? I mean, will the A ctor (the one with the three parameters) be called when I instantiate B using three parameters? And why do I need the default ctor?
I would really like to understand this mess.
- Jacco.
Last modification: Phantom - 01/03/02 at 11:35:02
I have these classes:
- Code:
class A
{
A(x,y,z);
~A;
};
class B : public A
{
dosomethingcool();
};
Now I want to instantiate class B, and I do it like this:
- Code:
B instance_of_B = new B(1,2,3);
This doesn't work. Why not? Shouldn't class B automatically use the ctor of A when it's not available in the same form in class B, just like any other method?
Right now, I fixed it like this:
- Code:
class B : public A
{
B(x,y,z) { A::A(x,y,z); }
dosomethingcool();
};
This doesn't work either; the compiler complains about a missing default ctor. So I added one to class A:
- Code:
class A
{
A();
A(x,y,z);
~A;
};
Now it compiles. But does this work like I expect? I mean, will the A ctor (the one with the three parameters) be called when I instantiate B using three parameters? And why do I need the default ctor?
I would really like to understand this mess.
- Jacco.
Last modification: Phantom - 01/03/02 at 11:35:02