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
  • 17,282
  • 10
  • 73
  • 131
daisy
  • 21,114
  • 28
  • 118
  • 236

2 Answers2

6

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

Community
  • 1
  • 1
Alok Save
  • 196,531
  • 48
  • 417
  • 525
  • 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 McLaughlin
  • 18,774
  • 3
  • 47
  • 56