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

时间:2017-03-31 04:47:06

标签: 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;
    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

Employee.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

0 个答案:

没有答案