I'm now writing C++ code to do some maths. However, it seems impossible to use normal constructors to initialize class members.
To get instantiated, the constructor of A is first called. By the time, p and q are just something like declaration so p and q don't get instantiated either. So I should be able to call constructor of B to instantiate them. Is that right? I think maybe my understanding of C++ classes is wrong somewhere so I post here to confirm.
class B{ // default constructor and copy constructor } class A{ private: B p; B q; public: explicit A(int _p, int _q); } // implementation A::A(int _p, int _q){ // some computing goes here so I can't apply // A::A(int _p, int _q):p{_p}, q{_q} // p = B{_p} // q = B{_q} // this works p{_p}; // Can't compile. q{_q}; // What's wrong with this? }