C++ 获取链接错误2005..无法找出原因

C++ 获取链接错误2005..无法找出原因,c++,class,linker,C++,Class,Linker,我只是试图创建一个基本类,但我得到链接错误2005 以下是我对班级的定义: Employee.h #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <iostream> #include <string> using namespace std; class Employee { private: string firstName; string lastName; string jobTitle;

我只是试图创建一个基本类,但我得到链接错误2005

以下是我对班级的定义:

Employee.h

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <iostream>
#include <string>
using namespace std;

class Employee {
private:
    string firstName;
    string lastName;
    string jobTitle;
    float baseSalary;
    float salary;
public:
    Employee(const string &, const string &,const string &, float);
    void calculateSalary(float);

    string getName() const;
    string getJobTitle() const;
    float getSalary() const;

    void print() const;

};
#endif

完整的错误消息是什么?您应该成对使用宏,
#endif
应该在
Employee.h
的末尾,这可能会导致您破坏.h文件末尾的@Pinky。格式化文章时出错。将修复。您不会碰巧在source.cpp中包含Employee.cpp,是吗?TL的可能副本;DR版本:Includes有效地将包含的文件粘贴到包含文件中,因此Source.cpp编译Employee.cpp的所有内容。Employee.cpp是独立编译的,因此现在您在两个单独的文件中有相同函数的两个版本,链接器将不知道使用哪个版本。永远不要包含.cpp文件。包含.h文件并让编译器编译.cpp。
#include <iostream>
#include <string>

using namespace std;

#include "Employee.h"

Employee::Employee(const string &first, const string &last, const string &title, float base) {
    firstName = first;
    lastName = last;
    jobTitle = title;
    baseSalary = base;
}

void Employee::calculateSalary(float baseSalary) {
    salary = baseSalary;
}

string Employee::getName() const{
    return firstName + " " + lastName;
}

string Employee::getJobTitle() const{
    return jobTitle;
}

float Employee::getSalary() const{
    return salary;
}

void Employee::print() const {
    cout << "Name: " << firstName << " " << lastName << endl;
    cout << "Job Title: " << jobTitle << endl;
    cout << "Salary: " << salary << endl;
}
Error   LNK2005 "public: void __thiscall Employee::calculateSalary(float)" (?calculateSalary@Employee@@QAEXM@Z) already defined in Employee.obj Lab 8 (2)   C:\Users\Zack Sloan\documents\visual studio 2017\Projects\Lab 8 (2)\Lab 8 (2)\Source.obj    1   
Error   LNK2005 "public: float __thiscall Employee::getSalary(void)const " (?getSalary@Employee@@QBEMXZ) already defined in Employee.obj    Lab 8 (2)   C:\Users\Zack Sloan\documents\visual studio 2017\Projects\Lab 8 (2)\Lab 8 (2)\Source.obj    1
Error   LNK2005 "public: void __thiscall Employee::print(void)const " (?print@Employee@@QBEXXZ) already defined in Employee.obj Lab 8 (2)   C:\Users\Zack Sloan\documents\visual studio 2017\Projects\Lab 8 (2)\Lab 8 (2)\Source.obj    1