You are not logged in.
Hello,
I started learning c++ under linux - I am just bored and want to learn something new. My problem is described below.
(it may look like a wall of text, but in fact it is simple)
I have 3 files: Employee.h, Employee.cpp, EmployeeTest.cpp. The code is:
Employee.h:
#include <iostream>
namespace Records
{
const int kDefaultStartingSalary = 30000;
class Employee
{
public:
Employee();
void promote(int inRaiseAmount = 1000);
void demote (int inDemeritAmount = 1000);
void hire ();
void fire ();
void display();
void setFirstName(std::string inFirstName);
std::string getFirstName();
void setLastName (std::string inLastName);
std::string getLastName();
void setEmployeeNumber(int inEmployeeNumber);
int getEmployeeNumber();
void setSalary(int newSalary);
int getSalary();
bool getIsHired();
private:
std::string mFirstName;
std::string mLastName;
int mEmployeeNumber;
int mSalary;
bool fHired;
};
}
Employee.cpp:
#include <iostream>
#include "Employee.h"
using namespace std;
namespace Records
{
Employee::Employee()
{
mFirstName = "";
mLastName = "";
mEmployeeNumber = -1;
mSalary = kDefaultStartingSalary;
fHired = false;
}
void Employee::promote(int inRaiseAmount)
{
setSalary(getSalary() + inRaiseAmount);
}
void Employee::demote(int inRaiseAmount)
{
setSalary(getSalary() - inRaiseAmount);
}
void Employee::hire()
{
fHired = true;
}
void Employee::fire()
{
fHired = false;
}
void Employee::display()
{
cout << "Employee: " << getLastName() << ", " << getFirstName() << endl;
cout << "--------------------------" << endl;
cout << (fHired ? "Current Employee" : "Former Employee") << endl;
cout << "Employee number: " << getEmployeeNumber() << endl;
cout << "Salary: $" << getSalary() << endl;
cout << endl;
}
//Accessors and setters
void Employee::setFirstName(string inFirstName)
{
mFirstName = inFirstName;
}
string Employee::getFirstName()
{
return mFirstName;
}
void Employee::setLastName(string inLastName)
{
mLastName = inLastName;
}
string Employee::getLastName()
{
return mLastName;
}
void Employee::setEmployeeNumber(int inEmployeeNumber)
{
mEmployeeNumber = inEmployeeNumber;
}
int Employee::getEmployeeNumber()
{
return mEmployeeNumber;
}
void Employee::setSalary(int inSalary)
{
mSalary = inSalary;
}
int Employee::getSalary()
{
return mSalary;
}
bool Employee::getIsHired()
{
return fHired;
}
}
EmployeeTest.cpp:
#include <iostream>
#include "Employee.h"
using namespace std;
using namespace Records;
int main (int argc, char** argv)
{
cout << "Testing Employee class." << endl;
Employee emp;
emp.setFirstName("Marni");
emp.setLastName("Kleper");
emp.setEmployeeNumber(71);
emp.setSalary(50000);
emp.promote();
emp.promote(50);
emp.hire();
emp.display();
return 0;
}
When I am trying to compile it with
g++ -W EmployeeTest.cpp -o EmployeeTest
I am getting the following errors:
/tmp/ccwiKDKD.o: In function `main':
EmployeeTest.cpp:(.text+0x9a): undefined reference to `Records::Employee::Employee()'
EmployeeTest.cpp:(.text+0xd1): undefined reference to `Records::Employee::setFirstName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
EmployeeTest.cpp:(.text+0x163): undefined reference to `Records::Employee::setLastName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
EmployeeTest.cpp:(.text+0x1ad): undefined reference to `Records::Employee::setEmployeeNumber(int)'
EmployeeTest.cpp:(.text+0x1e1): undefined reference to `Records::Employee::setSalary(int)'
EmployeeTest.cpp:(.text+0x1f4): undefined reference to `Records::Employee::promote(int)'
EmployeeTest.cpp:(.text+0x207): undefined reference to `Records::Employee::promote(int)'
EmployeeTest.cpp:(.text+0x212): undefined reference to `Records::Employee::hire()'
EmployeeTest.cpp:(.text+0x21d): undefined reference to `Records::Employee::display()'
collect2: ld returned 1 exit status
I know that I must had made a simple mistake somewhere...but I dunno where - and I would be gratefull for any help.
Best regards,
Mike.
Last edited by praavDa (2009-03-31 07:35:15)
gvim -c "exec \"normal itYNQ#v'Z#ABG#GUR#BAYL#BAR\"|%s/#/ /g|normal ggVGg?ggVG~"
Offline
Seems like just a mistake on your command line. Try:
g++ -o EmployeeTest EmployeeTest.cpp Employee.cpp
You forgot to include the other .cpp file.
Good luck!
Offline
tom5760, thank You very much - I knew this one was simple. You were right, I forgot to include other cpp files...stupid me:)
Kudos, Mate and thanks one more time.
Last edited by praavDa (2009-03-31 07:36:34)
gvim -c "exec \"normal itYNQ#v'Z#ABG#GUR#BAYL#BAR\"|%s/#/ /g|normal ggVGg?ggVG~"
Offline