請看看我的代碼。我在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