1

Suppose the following constructor:

class Needed
{
public: 
    Needed () {}
    Needed (const char *name) {}
};


class Dummy
{
public:
    Dummy (): needed ( "Jimmy" ) {}

private:
    Needed needed;
};

So, did I initialized needed twice here?

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
daisy
  • 22,498
  • 29
  • 129
  • 265

2 Answers2

6

No you initialized it only once in the Member Initializer List.

Community
  • 1
  • 1
Alok Save
  • 202,538
  • 53
  • 430
  • 533
  • The list itself doesn't "initialize" the member object, though. The object is *always* initialized. The list just says *how* to initialize it. – Kerrek SB Jan 31 '12 at 15:49
1

No, it only gets initialized once for each Dummy instance. You just supplied the arguments for its initialization (and selected which constructor to use).

James M
  • 18,506
  • 3
  • 48
  • 56