c++ - 类未定义 C++

标签 c++ oop

在测试中,我试图创建对象 partTimeEmployee,但出现 undefined reference 错误,我不明白为什么?我不明白这个错误,因为我传递了正确类型的数据。我的 .cpp 和 .h 不包括在内吗?

test.cpp: (.text+0xb7): 未定义对“partTimeEmployee(std::basic_string, std::allocator >)”的引用

工作.h

#ifndef WORK_H
#define WORK_H

using namespace std;
#include <string>

class work{
        public:
          void DisplayMe();
          work(string x,string y);
          work();
          ~work();

        string name;
        string id;
};
#endif

工作.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib.h>
#include "work.h"

using namespace std;

work::work(){
        cout<<name<<"in default work constructor"<<endl;
}

work::~work(){
        cout<< name << " calling work destructor. " << endl;
}

work::work(string x, string y){

        name = x;
        id = y;

        cout << "in parent constructor" <<endl;
}

void work::DisplayMe(){
        cout << "NAME: " << name << "    ID#: " << id <<endl;
}

员工.h

#ifndef EMPLOYEE_H
#define EMPLOYEE_H

include "work.h"
using namespace std;

class Employee : public sfasu{

        public:
          Employee();
          Employee(string x);
          ~Employee();

        string department;

};
#endif

员工.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib.h>
#include "Employee.h"

using namespace std;

Employee::Employee(){
        cout<<name<<"in default sfasu constructor"<<endl;
}

Employee::~Employee(){
        cout<< name << " calling parent destructor. " << endl;
}

Employee::Employee(string x){

        department = x;

        cout << "in parent constructor" <<endl;
}

partTimeEmployee.h

#ifndef PARTTIMEEMPLOYEE_H
#define PARTTIMEEMPLOYEE_H

#include "Employee.h"
using namespace std;

class partTimeEmployee : public Employee{

        public:
          partTimeEmployee();
          partTimeEmployee(string x);
          ~partTimeEmployee();

        string hourly_wage;

};
#endif

partTimeEmployee.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib.h>
#include "partTimeEmployee.h"

using namespace std;

partTimeEmployee::partTimeEmployee(){
        cout<<"in default partTimeEmployee constructor"<<endl;
}

partTimeEmployee::~partTimeEmployee(){
        cout<< " calling FTP destructor. " << endl;
}

partTimeEmployee::partTimeEmployee(string x){

        hourly_wage = x;

        cout << "partTimeEmployeeconstructor" <<endl;
}

测试.cpp

#include <iostream>
#include <iomanip>
#include "sfasu.h"
#include "Employee.h"
#include "partTimeEmployee.h"
using namespace std;

int main(){

partTimeEmployee one("data");
}

最佳答案

改变

class partTimeEmployee : public partTimeEmployee

class partTimeEmployee : public Employee

关于c++ - 类未定义 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33400408/

相关文章:

c++ - 函数执行失败后的代码 - C++

C++搜索算法——处理海量数据

c++ - 在 C/C++ 中监视变量访问

c++ - 导致无法解析的外部符号的常量引用参数

c# - 平台构建器中的 DLL

c++ - C++ 中的通用(几乎)自描述参数与 GUI 相结合?

C++:三规则,为什么?

c# - 接口(interface)和对象反序列化

python - 如何使用类中的方法来比较该类的两个对象

c++ - 继承和重载默认构造函数