By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

Erros: Overloaded constructor not found, EOF found

P: 3
Hi,

I have got seven error and I dont find why compiler find error..

//commission class definition
#ifndef COMMISSION_H
#define COMMISSION_H

#include <string>
using std::string;

class Commission
{
public:
Commission(const string &,const string &,const string &,const string &,double=0.0,double=0.0);

void setFirstName(const string &);
string getFirstName() const;

void setLastName(const string &);
string getLastName() const;

void setSocialSecurityNumber(const string &);
string getSocialSecurityNumber() const;

void setGrossSales(double);
double getGrossSales() const;

void setCommissionRate(double);
double getCommissionRate() const;

double earnings() const;
void print() const;
private:
string firstName;
string lastName;
string socialSecurityNumber;
double grossRate;
double commmisionRate;
};

#endif

//base class definition
#ifndef BASE_H
#define BASE_H

#include <string>
using std::string;

#include "commission.h"

class Base
{
public:
Base(const string &,const string &,const string &,const string &,double=0.0,double=0.0,double=0.0);
void setBaseSalary(double);
double getBaseSalary() const;

double earnings() const;
void print() const;
private:
double baseSalary;
};

#endif


//Commission class member function definitions
#include <iostream>
using std::cout;

#include "commission.h"

Commission::Commission(const string &first,const string &last,const string &ssn,double sales,double rate)
:firstName(first),lastName(last),socialSecurityNum ber(ssn)
{
setGrossSales(sales);
setCommissionRate(rate);
}

void Commission::setFirstName(const string &first)
{
firstName = first;
}

string Commission::getFirstName() const
{
return firstName;
}

void Commission::setLastName(const string &last)
{
lastName = last;
}

string Commission::getLastName() const
{
return lastName;
}

void Commission::setSocialSecurityNumber(const string &ssn)
{
socialSecurityNumber = ssn;
}

string Commission::getSocialSecurityNumber() const
{
return socialSecurityNumber;
}

void Commission::setGrossSales(double sales)
{
grossSales = (sales<0.0 ? 0.0 : sales);
}

double Commission::getGrossSales() const
{
return grossSales;
}

void Commission::setCommissionRate(double rate)
{
grossRate = (rate>0.0 && rate<1.0) rate : 0.0;
}

double Commission::getCommissionRate() const
{
return grossRate;
}

double Commission::earnings() const
{
return getCommissionRate() * getGrossSales();
}

void Commission::print() const
{
cout << "Commision employee :"
<< getFirtName() << ' ' << getLastName()
<< "\nsocial security number :" << getSocialSecurityNumber()
<< "\ngross sales :" << getGrossSales()
<< "\ncommission rate :" << getCommissionRate();
}


//base class member function definitions
#include <iostream>
using std::cout;

#include "base.h"

Base::Base(const string &first,const string &last,const string &ssn,double,double,double)
:Commission(first,last,ssn,sales,rate)
{
setBaseSalary(salary);
}

void Base::setBaseSalary(double salary)
{
baseSalary = (salary<0.0) ? 0.0 ? salary;
}

double Base::getBaseSalary() const
{
return baseSalary;
}

double Base::earnings() const
{
return getBaseSalary() + Commission::earnings(9;
}

void Base::print() const
{
cout << "base salaried ";

Commission::print();

cout < "\nbase salary: " << getBaseSalary();
}


//test main
#include <iostream>
using namespace std;

#include <iomanip>
using std::setprecision;

#include "base.h"

int main()
{

Commission x("Sue","Jones","2222-1111",10000,.06);

Commission *xPtr = 0;

Base y("Bob","Lewis","33-3333",5000,.04,300);
Base *yPtr = 0;

cout << fixed << setprecision(20);

x.print();
cout << "\n\n";
y.print();

xPtr = &x;
xPtr->print();

yPtr = &y;
yPtr->print();

xPtr = &y;
xPtr->print();

return 0;
}


and I find this errorr ...

C:\Program Files\Microsoft Visual Studio\MyProjects\poly\commissionsource.cpp(8) : error C2511: 'Commission::Commission' : overloaded member function 'void (const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
> &,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,double,double)' not found in 'Commission'
c:\program files\microsoft visual studio\myprojects\poly\commission.h(9) : see declaration of 'Commission'
C:\Program Files\Microsoft Visual Studio\MyProjects\poly\commissionsource.cpp(80) : fatal error C1004: unexpected end of file found
basesource.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\poly\basesource.cpp(8) : error C2511: 'Base::Base' : overloaded member function 'void (const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const class st
d::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,double,double,double)' not found in 'Base'
c:\program files\microsoft visual studio\myprojects\poly\base.h(11) : see declaration of 'Base'
C:\Program Files\Microsoft Visual Studio\MyProjects\poly\basesource.cpp(37) : fatal error C1004: unexpected end of file found
main.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\poly\main.cpp(13) : error C2664: '__thiscall Commission::Commission(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const class std::basic_string<cha
r,struct std::char_traits<char>,class std::allocator<char> > &,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char
> > &,double,double)' : cannot convert parameter 4 from 'const int' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &'
Reason: cannot convert from 'const int' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Program Files\Microsoft Visual Studio\MyProjects\poly\main.cpp(17) : error C2664: '__thiscall Base::Base(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const class std::basic_string<char,struct std
::char_traits<char>,class std::allocator<char> > &,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,double
,double,double)' : cannot convert parameter 4 from 'const int' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &'
Reason: cannot convert from 'const int' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Program Files\Microsoft Visual Studio\MyProjects\poly\main.cpp(32) : error C2440: '=' : cannot convert from 'class Base *' to 'class Commission *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
Dec 24 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Expand|Select|Wrap|Line Numbers
  1. //The member definition:
  2. Commission::Commission(const string &first,const string &last,const string &ssn,double sales,double rate)
  3.  
Expand|Select|Wrap|Line Numbers
  1. //the class declaration:
  2. Commission(const string &,const string &,const string &,const string &,double=0.0,double=0.0);
  3.  
For starters, the constructor in your class has 4 string& arguments but the construcor definition has only 3.

Fix that and repost if you still have problems.
Dec 24 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.