I have 2 classes in the same file employee and employeeException. If i define a constructor for employee , i will be unable to define a constructor for employeeException , vice versa . Trying to define constructors for both classess would cause the following compilation error :
no matching function call to employee
#include <iostream>
#include <string>
using namespace std;
class employee
{
public:
double operator + (employee);
bool operator == (employee);
employee(int);
double getSalary();
private:
double salary;
};
class employeeException
{
public:
employeeException(string);
void printmessage();
private:
employee e;
string message;
};
int main()
{
employee A(400);
employee B(400);
employee C = A+B;
if ( A == B)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
cout<<C.getSalary();
}
employee::employee(int salary)
{
this->salary = salary;
}
double employee::operator + (employee e)
{
double total;
total = e.salary + this->salary;
return total;
}
double employee::getSalary()
{
return this->salary;
}
bool employee::operator == (employee e)
{
if ( e.salary == this->salary)
{
return true;
}
else
{
return false;
}
}
employeeException::employeeException(string message)
{
this->message = message;
}
void employeeException::printmessage()
{
cout<<endl
<<this->message
<<endl;
}
Questions
1) From the above , it seems that we cannot define constructors of 2 different class in the same file , are there any way to overcome this
2) Can someone give me a explaination why we cant define constructors of 2 different class in the same file
Additional info
I am using Quincy 2005 to compile the code
You can use this online compiler: http://www.compileonline.com/compile_cpp0x_online.php
Conclusion It seems i have to add the default constructor employee() for it to work , thanks to everyone for helping me out one way or another