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

下面是小弟我的程序,哪位好心人能帮帮忙,感激不尽

2012-04-19 
下面是我的程序,哪位好心人能帮帮忙,感激不尽。//student.h#includestringusing namespace stdclass stu

下面是我的程序,哪位好心人能帮帮忙,感激不尽。
//student.h
#include<string>
using namespace std;
class student
{ public:
  void display();
  private:
  int num;
  string name;
  char sex;
};

//student.cpp
#include<iostream>
#include"student.h"
using namespace std;
void student::display()
{ cout<<"num:"<<num<<endl;
  cout<<"name:"<<name<<endl;
 cout<<"sex"<<sex<<endl;
}

//main.cpp
#include<iostream>
#include"student.h"
using namespace std;
int main()
{ student stud;
  stud.display();
  return 0;
}

编译后显示 student.h(5) : error C2011: 'student' : 'class' type redefinition

小弟是fish,希望大侠们不吝赐教

[解决办法]

C/C++ code
#include"student.h"using namespace std;int main(){ student stud;  stud.display();  return 0;}
[解决办法]
我能运行了。
C/C++ code
#include<iostream>#include"student.h"using namespace std;int main(){     student stud;    stud.display();    cout<<"程序没有问题,不过student.cpp里缺了头文件,string虽然非必要(因为student.h里已经包含),但逻辑上是必须包含的"<<endl;    return 0;} 

热点排行