Why don't we have different copies of static variables for different objects?
Because they will be members of the copy .
The main characteristic of static elements is that they are shared by all instances of the class.
Since the $ 9.4.2 / 1 section of C ++ Standard (2003) says:
A static data member is not part of a subobject of a class. There is only one copy of the static data element shared by all objects in the class.
Since only the standard decides what C ++ is and what not, since C ++ was developed!
Static elements are more like global objects. The same copy applies to all objects!
See this post for a detailed answer: Static class members occupy memory if an object of this class has not been created?
A static member is not associated with a specific instance.
If you need different member values ββfor each instance, you should use instance members (remove the static keyword).
By definition, a static object is one that is shared by all instances of the class. Ordinary members do not have this property.
This definition is static - there is one copy of the data. It is separately stored, most likely, together with all other static data of the library or application.
static
Because what static means in this context.
Since the static elements of a class are stored separately in the BSS section, each instance of the class has the same value.
Source: https://habr.com/ru/post/1337648/More articles:Are there any good open source web servers for ASP.NET MVC applications? - c #Why does the DejaVu Sans Mono font look different (G) Vim and Emacs? - vimCan I use Subversion for a low quality 3G network? - svnAn unobtrusive way to make $ (document) .ready (.....) in rails 3 - javascriptDIsable Python module - pythonstore php objects in html form element and pass php objects via GET method? - phpUse AJAX or Multithreading to Speed ββUp Page Loading - multithreadingIndirect virtual function call from Destructor - c ++Controls inside UpdatePanel - css styles disappear on update (IE8) - asp.netHow to make a poster in Lyx? - lyxAll Articles