1 year ago
#333146
kevin patel
What is wrong with my code? I am getting "undefined reference to " errors
i am a beginner programmer currently learning about classes and objects, for some reason my code is getting the error "undefined reference to " whenever i try to run the code. This is testemployee.cpp
#include "employee.h"
#include <iostream>
using namespace std;
int main()
{
employee one;
one.modifyfirstname("kevin");
one.modifylastname("Patel");
cout<<one.returnfirstname()<<one.returnlastname();
}
This is employee.cpp
#include "employee.h"
employee::employee()
{
id=0;
firstname="";
lastname="";
birth="";
address="";
yearhired=0;
salary=0.0;
areacode=0;
telephone="";
}
int employee::returnid()
{
return id;
}
string employee::returnfirstname()
{
return firstname;
}
void employee::modifyfirstname(string firstname1)
{
firstname=firstname1;
}
string employee::returnlastname()
{
return lastname;
}
void employee::modifylastname(string lastname1)
{
lastname=lastname1;
}
This is employee.h
#include <string>
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
using namespace std;
class employee
{
private:
int id;
string firstname;
string lastname;
string birth;
string address;
int yearhired;
double salary;
int areacode;
string telephone;
public:
employee();
int returnid();
string returnfirstname();
void modifyfirstname(string);
string returnlastname();
void modifylastname(string);
};
#endif
the error
/usr/bin/ld: /tmp/ccqnCjc9.o: in function main': testemployee.cpp:(.text+0x26): undefined reference to
employee::employee()'
/usr/bin/ld: testemployee.cpp:(.text+0x6e): undefined reference to employee::modifyfirstname(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' /usr/bin/ld: testemployee.cpp:(.text+0xd4): undefined reference to
employee::modifylastname(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: testemployee.cpp:(.text+0x10b): undefined reference to employee::returnfirstname[abi:cxx11]()' /usr/bin/ld: testemployee.cpp:(.text+0x140): undefined reference to
employee::returnlastnameabi:cxx11'
collect2: error: ld returned 1 exit status
i've tried to compile my code
c++
class
linker
header-files
0 Answers
Your Answer