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

帮忙看一下这样C++程序出错在哪里?

鸿鹄 发布于 2010-03-14 11:21, 653 次点击
帮忙看一下是什么问题,
文件student.h
#include <string>
using namespace std;
class student
{
public:
     void display();
     void set_value();

private:
    int num;
    string name;
    char sex;
};

文件:student.cpp
#include <iostream>
#include "student.h"
  void student:: display()
     {
     cout<<"num:"<<num<<endl;
     cout<<"name:"<<name<<endl;
     cout<<"sex:"<<sex<<endl;
    }
   
 void student::set_value()
    {
        cin>>num>>name>>sex;
}

文件:main.cpp
#include <iostream>
#include "student.h"
using namespace std;
int main()
{
 student stud;
 stud.set_value();
 stud.display();
 return 0;

}

运行之后出现:
--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall student::display(void)" (?display@student@@QAEXXZ)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall student::set_value(void)" (?set_value@student@@QAEXXZ)
Debug/main.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Creating browse info file...

main.exe - 3 error(s), 0 warning(s)
3 回复
#2
ltyjyufo2010-03-14 12:00
不好意思看错了。。。。。。。。
#3
iou4022010-03-14 12:04
我这运行没问题。
#4
鸿鹄2010-03-15 18:38
搞定了。还是谢谢你们。
1