0

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?

2
  • 1
    Copy constructor normally I would expect Commented Jul 21, 2014 at 12:08
  • You really can't initialize something with assignment. By that time, it's already initialized. Commented Jul 21, 2014 at 12:10

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.