Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Endure order of construction?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Francesco S. Carta, post: 3950399"] You don't need to do anything to ensure that, you're already guaranteed that those object will be fully constructed when the processing flow enters into the body of BigClass::BigClass(). And that's true also if you don't specify ": A_(), B_()" right behind that function body - actually, that specification is superfluous. The order with which the objects will be called is based on the order of their declarations in BigClass. First A_, then B_, then Spider_. In any case, you have messed up something - have you typed the code in the newsreader? As Marcel correctly pointed out, you're trying to call a non-existing "BigClass::operator()(A*, B*)" Your code should look like the following: ------- #include <iostream> using namespace std; class A {}; class B {}; class Spider { public: Spider(const A* a, const B* b) : a(a), b(b) { } void print() { cout << "Spider_.a == " << a << endl; cout << "Spider_.b == " << b << endl; } private: const A* a; const B* b; Spider(){}; }; class BigClass{ public: BigClass() : Spider_(&A_,&B_) { } void print() { cout << "&bc.A_ == " << &A_ << endl; cout << "&bc.B_ == " << &B_ << endl; Spider_.print(); } private: A A_; B B_; Spider Spider_; }; int main() { BigClass bc; bc.print(); return 0; } ------- Note that you don't need to explicitly call the constructors for A and B, they will be called automatically before of the "Spider_(&A_,&B_)" initializer. The print() functions have been added just to test it. Have good time, Francesco [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Endure order of construction?
Top