Nested Constructors
This is probably simple but...
Class A : public B
When creating a class A B''s constructor didn''t get called (I think). Is there something I need to do to make sure it gets kicked off?
Many thanks
Chris
Chris Brodie
B's constructor will always be called, before executing the body of A's constructor.
A simple program to show the constructor sequence is the following:
When compiled and executed, this will give the following output:
B::B()
A::A()
A::~A()
B::~B()
HTH
Edited by - JungleJim on May 8, 2001 8:01:15 AM
Edited by - JungleJim on May 8, 2001 8:02:03 AM
A simple program to show the constructor sequence is the following:
|
When compiled and executed, this will give the following output:
B::B()
A::A()
A::~A()
B::~B()
HTH
Edited by - JungleJim on May 8, 2001 8:01:15 AM
Edited by - JungleJim on May 8, 2001 8:02:03 AM
Some useful C++ links:Free multiplatform ANSI C++ Standard Library implementationVisual C++ 6.0 STL fixesVisual C++ 6.0 noncompliance issuesC++ FAQ Lite
If you have a constructor that needs parameters, you call it like so;
Just the same as parameter initialisation.
|
Just the same as parameter initialisation.
class _2dpoint
{
public:
int x, y;
_2dpoint(int nx, int ny)
{
x = nx;
y = ny;
}
};
class _3dpoint : public _2dpoint
{
public:
int z;
_3dpoint(int nx, int ny, int nz) : _2dpoint(nx, ny)
{
z = nz;
}
};
hope you get the point
Arkon
[QSoft Systems]
{
public:
int x, y;
_2dpoint(int nx, int ny)
{
x = nx;
y = ny;
}
};
class _3dpoint : public _2dpoint
{
public:
int z;
_3dpoint(int nx, int ny, int nz) : _2dpoint(nx, ny)
{
z = nz;
}
};
hope you get the point
![](smile.gif)
Arkon
[QSoft Systems]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement