注册 登录
编程论坛 C++教室

怎么使类声明和成员函数分离

lionmusicyj 发布于 2008-11-25 23:14, 1321 次点击
//student.h
class student
{
   public:
      student(int n):num(n){}
      void display();
   private:
      int num;
      string name;
      char sex;
};
//student.cpp
#include <iostream>
#include "student.h"
void student::display()
{
  cout<<"num"<<num;
}

为什么我写这个主函数会出现链接错误?
#include <iostream>
#include <string>
#include "student.h"
using namespace std;
int main()
{
  student s(7);
  s.display();
  system("pause");
  exit(1);
}
希望大家指教下小弟哈~!
3 回复
#2
pascale2008-11-26 11:20
student.h里面缺少头文件
顺便system()和exit(1)是哪个头函数里面声明的呢?
#3
studentm2008-11-26 13:05
你的.h文件被链接了两次,在定义头文件的时候 要  
#ifndef  _XXXXXX_H_
#define  ...
...
#endif

这样你的错误就能解决了
system 调用系统命令,即dos下的命令 systme(“tree 。。。”)
#4
LJCX2008-11-26 18:44
同意3楼的!
1