Given:
class Foo {
private:
static int cntFoos;
//... stuff...
public:
Foo() { cntFoos++; }
~Foo() { cntFoos--; }
};
... where "stuff" may be any set of properties. (The idea is to have a counter of instances of that class)
Then:
Foo aFoo;
Foo twoFoo=aFoo;
Will invoke the automatic copy constructor, and thus I'd miss counting this one.
Is there a way to keep that counter reflecting the new instances created automatically? If I implement the explicit copy constructor, I will have to assign all the properties one by one. However, I want a shallow, memberwise copy. I don't need to perform a deep copy, so it seems like a lot of unnecessary work to implement an explicit copy constructor.