Hi very new to C++, trying to compile a single class without an int main() method and I get this error message:
anth@linux:> g++ Employee.cpp -o employee
/usr/lib/gcc-lib/i586-suse-linux/3.3.4/../../../crt1.o(.text+0x18): In function`_start':
../sysdeps/i386/elf/start.S:115: undefined reference to `main'
collect2: ld returned 1 exit status
Not a clue why, I've copied it straight from a text book. If I put a main() in it compiles fine. Maybe I shouldn't complain but its just the book does not specify a main so I'd like to know how I can do it without one.
Here is the header file and the implementation just incase.
Thanks guys,
Anthony.
Code:
// This is the header file employee.h
// This is the interface for the class Employee
// This is primarily intended to be used as a base class to derive
// classes for different kinds of employees.
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using std::string;
namespace QuinnEmployees
{
class Employee
{
public:
Employee();
Employee(string theName, string theSsn);
string getName() const;
string getSsn() const;
double getNetPay() const;
void setName(string newName);
void setSsn(string newSsn);
void setNetPay(double newNetPay);
void printCheck() const;
private:
string name;
string ssn;
double netPay;
};
} // QuinnEmployees
#endif // EMPLOYEE_H
Code:
// This is the file Employee.cpp
// This is the implementation for the class Employee.
// The interface for the class Employee is in the header file employee.h
#include <string>
#include <cstdlib>
#include <iostream>
#include "Employee.h"
using std::string;
using std::cout;
namespace QuinnEmployees
{
Employee::Employee() : name("No name yet"), ssn("No number yet"), netPay(0)
{
// Do nothing.
}
Employee::Employee(string theName, string theNumber) : name(theName), ssn(theNumber), netPay(0)
{
// Do nothing.
}
string Employee::getName() const
{
return name;
}
string Employee::getSsn() const
{
return ssn;
}
double Employee::getNetPay() const
{
return netPay;
}
void Employee::setName(string newName)
{
name = newName;
}
void Employee::setSsn(string newSsn)
{
ssn = newSsn;
}
void Employee::setNetPay(double newNetPay)
{
netPay = newNetPay;
}
void Employee::printCheck() const
{
cout << "\n ERROR: printCheck FUNCTION CALLED FOR AN\n"
<< "UNDIFFERENTIATED EMPLOYEE. Aborting the program.\n"
<< "Check with the author of the program about this bug.";
exit(1);
}
} // QuinnEmployees