user53670
user53670

Reputation:

why can we declare static object of a class inside the same class?

class A
{
   static const A a;
}

Why we can do this , while we cannot do this without the word static?

Upvotes: 0

Views: 298

Answers (1)

SLaks
SLaks

Reputation: 887315

A static member has just one value; it's essentially a global variable scoped to the class declaration.

A non-static member is a value that appears in each class instance.
It doesn't make sense for a class to directly contain itself, since that would consume an infinite amount of memory.

You may want a pointer.

Upvotes: 4

Related Questions