简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM