首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

c++程序修改,不知道哪错了。该如何处理

2013-04-20 
c++程序修改,不知道哪错了。#include iostream#include stringusing namespace stdclass Part{public:

c++程序修改,不知道哪错了。
#include <iostream>
#include <string>
using namespace std;
class Part
{
public:
Part(char *pname="no name")
{
strncpy(name,pname);
noofpart++;
cout<<"create the no:"<<noofpart<<"of part"<<endl;
}
~Part()
{
noofpart--;
cout<<"destroy the no:"<<noofpart<<"of part"<<endl;
{
noofpart--;
cout<<"destroy the no:"<<noofpart<<"of part"<<endl;
}
static int number()
{
return no;
}
private:
static int noofpart=0;
int no;
char name[40];
};
int main()
{
Part p1;
Part p2;
return 1;
}
[解决办法]


#include <iostream>
#include <string>

using namespace std;

class Part
{
public:
Part(char *pname="no name")
{
strncpy(name,pname,40);//这里漏了个参数
noofpart++;
cout<<"create the no:"<<noofpart<<" of part"<<endl;
}
~Part()
{
noofpart--;
cout<<"destroy the no:"<<noofpart<<" of part"<<endl;
}
int number() const  //这个函数不能是static
{
return no;
}
private:
static int noofpart;//static数据成员要在类外定义时初始化。
int no;
char name[40];
};

int Part::noofpart = 0;

int main()
{
Part p1;
Part p2;
return 1;
}

热点排行