gpt4 book ai didi

c++ - 类未定义 C++

转载 作者:行者123 更新时间:2023-11-28 00:10:28 24 4
gpt4 key购买 nike

在测试中,我试图创建对象 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com