I was testing which constructors are called in when a derived and then base class objects are created. My program couted 0 if it was the base class and 1 if it was the base class. I ran it and it returned 01 for the derived class and 0 for the base class. The derived class surprised me greatly because it seems as thought it calls the base class and then the derived class. Is this information correct?
CPPRULZ 0 Junior Poster in Training
Recommended Answers
Jump to PostThe order of class object constuction (reduced C++ rules, apply recursively):
1. direct base class(es) constructor(s)
2. this nonstatic data member(s) constructor(s)
3. this constructorRevert the order for destruction.
Try this:
class Member { public: Member(const char* where = ""):whom(where) { cout << …
Jump to PostYes but doesn't it seem terribly inefficient to call all of the constructors in that order automatically? Is there any way to stop it?
Yes, of course: stop using this inefficient ;) language C++, switch to Visual Basic (or better to Fortran 66)...
Yet another way to go: never declare …
All 5 Replies
ArkM 1,090 Postaholic
CPPRULZ 0 Junior Poster in Training
ArkM 1,090 Postaholic
CPPRULZ 0 Junior Poster in Training
ArkM 1,090 Postaholic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.