C++ 代码的修正

来源:百度知道 编辑:UC知道 时间:2024/05/11 21:40:42
请问以下代码错在哪
#include<iostream.h>
class CountsItself
{
static int objectcount;
int loCalCount;
public:
void setcount()
{
loCalCount=objectcount++;
}
void displaycount()
{
cout<<"Total number of obects: "<<loCalCount;
}
};
int CountsItself::objectCount;
int main()
{
CountsItself count1,count2,count3;
count1.setcount();
count2.setcount();
count3.setcount();
}
objectCount那是小问题..不在这..
上面的代码是打印小于所创建的对象总数的一个数.

#include<iostream.h>
class CountsItself
{
static int objectcount;
int loCalCount;
public:
void setcount()
{
loCalCount=objectcount++;
}
void displaycount()
{
cout<<"Total number of obects: "<<loCalCount;
}
};
int CountsItself::objectcount;
void main()
{
CountsItself count1,count2,count3;
count1.setcount();
count2.setcount();
count3.setcount();
}