请看看我的代码。我在Visual Studio中得到的错误是简单的程序不会编译
error LNK2019: unresolved external symbol "public: int __thiscall Employee::getId(void)" ([email protected]@@QAEHXZ) referenced in function _main
Employee.h
#ifndef EMPLOYEES
#define EMPLOYEES
#include <string>
#include <iostream>
using namespace std;
class Employee
{
private:
string name;
int id;
public:
Employee();
Employee(string nm, int idd);
string getName();
int getId();
};
#endif
Employee.cpp
#include "Employee.h"
#include <string>
Employee::Employee()
{
name="unknown";
id=0;
}
Employee::Employee(string nm, int idd)
{
name=nm;
id=idd;
}
string Employee::getName()
{
return name;
}
int Employee::getId()
{
return id;
}
司机
#include <iostream>
#include <string>
#include "Employee.h"
using namespace std;
int main()
{
Employee bob("bob", 3);
cout << bob.getId();
}
你最好不要使用“using namespace std;”在标题(不涉及你的问题)。 – ysdx 2011-04-09 23:58:27
编译和链接行怎么样? – 2011-04-09 23:58:40
你如何编译你的程序? – Muggen 2011-04-09 23:59:04