It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
9年前关闭。
如何在构造函数中放置一个计数器?
9年前关闭。
如何在构造函数中放置一个计数器?
最佳答案
如果要计算已创建对象的数量,可以使用静态(类)变量
class CountingClass {
private:
static int count;
public:
CountingClass() {
++CountingClass::count;
}
};
10-08 08:55