📌  相关文章
📜  为什么构造函数在 C++ 代码示例中不能是静态的

📅  最后修改于: 2022-03-11 14:44:49.775000             🧑  作者: Mango

代码示例1
static variable are those variable declared with static and i will be refer to the common property of all the objects in a java and it is mainly used for memory managment in java. constructor is used to inilialize the objects and it is automatically called at time of object creation.

It is not possible in the constructor because static member variables are not associated with each object of the class. It is shared by all objects. If you initialize the static variable into the constructor then it means that you are trying to associate with a particular instance of class. Since this is not possible, it is not allowed.