user695652
user695652

Reputation: 4275

c++: initialization list with no default constructor

If I have a class A without default constructor and a class B

class B {
  private:
    A m_a;

  public:
    B(A a) : m_a(a) {} 
};

How is m_a now initialized? By the assignment operator of A or by the copy constructor?

Upvotes: 0

Views: 298

Answers (1)

Mike Seymour
Mike Seymour

Reputation: 254431

By the copy constructor, since it's being copy-initialised.

The assignment operator is used for assignment to an existing object, never for initialisation of a new object.

Upvotes: 3

Related Questions