c++ - Initialize member before base constructor. Possible? -
this question has answer here:
i have following code:
class a{ public: a(int* i){ std::cout << "in a()" << << std::endl; } }; class b: public a{ public: b(): i{new int{10}}, a{i}{ std::cout << "in b()" << std::endl; } private: int* i; }; int main() { b b; }
in a
constructor have 0 (which expected). want initialize i
before. possible @ all?
i
data member of class b
, in order created, object of class b
has created first. answer, no.
Comments
Post a Comment