1

The following code can be compiled and run. I am wondering when the constructor of v is called. Is it called before the constructor of A is called? Also I am wondering whether the following code satisfies c++ standard.

#include <vector>
#include <iostream>

class A{
private:
    std::vector<int> v;
public:
    A(int b) { v.push_back(b); };
};

int main() {
    A a(1);
    return 0;
}
andy90
  • 525
  • 5
  • 19
  • 1
    Before the body of `A::A` is entered: _"..Before the compound statement that forms the function body of the constructor begins executing, initialization of all direct bases, virtual bases, and __non-static data members__ is finished. ..."_ from: http://en.cppreference.com/w/cpp/language/initializer_list – Richard Critten Jun 07 '18 at 17:55
  • 1
    And since there is a second question here, which obviously is not answered in the duplicate - yes, this code is standard-complying. – SergeyA Jun 07 '18 at 17:56

0 Answers0