Welcome to Dream.In.Code
Click Here
Getting C++ Help is Easy!

Join 117,572 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 1,949 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Explicitly calling a base class constructor &

 
Reply to this topicStart new topic

Explicitly calling a base class constructor &, unexpected end-of-file error

chaoticabyss99
post 19 Jul, 2008 - 11:41 PM
Post #1


D.I.C Head

**
Joined: 14 Jun, 2008
Posts: 90


My Contributions


I'm receiving 2 error messages in my program. I'm pretty sure you can explicitly call a base class constructor and I thought I was doing it right. But apparently not. The first one is:

error C2511: 'OverNightPackage::OverNightPackage(const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,double,double)' : overloaded member function not found in 'OverNightPackage'

which is referring to this piece
CODE
OverNightPackage::OverNightPackage(
        const string &sname, const string &saddress, const string &scity, const string &sstate,
        const string &szip, const string &rname, const string &raddress, const string &rcity,
        const string &rstate, const string &rzip, double shipWeight, double shipRate)
        //explicitly call base-class constructor
        : Package(sname, saddress, scity, sstate, szip, rname, raddress, rcity, rstate, rzip, shipWeight, shipRate)
and then the second error message is:

fatal error C1004: unexpected end-of-file found

which is referring me back to the beginning of the program.

Can, and will, anyone help me figure this out please?
User is offlineProfile CardPM

Go to the top of the page


skaoth
post 19 Jul, 2008 - 11:46 PM
Post #2


D.I.C Regular

Group Icon
Joined: 7 Nov, 2007
Posts: 333



Thanked 8 times

Dream Kudos: 100
My Contributions


For us to be of more help, you will need to provide the complete code for the OverNightPackage class, Package class (implementation and definition if in .h and .cpp files), and what ever file your compiler is complaining about resulting in this atal error C1004: unexpected end-of-file found
User is offlineProfile CardPM

Go to the top of the page

chaoticabyss99
post 19 Jul, 2008 - 11:50 PM
Post #3


D.I.C Head

**
Joined: 14 Jun, 2008
Posts: 90


My Contributions


QUOTE(skaoth @ 19 Jul, 2008 - 11:46 PM) *

For us to be of more help, you will need to provide the complete code for the OverNightPackage class, Package class (implementation and definition if in .h and .cpp files), and what ever file your compiler is complaining about resulting in this atal error C1004: unexpected end-of-file found



OK, here is the entire program I have. I have made this into just 1 file:

CODE
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string>

using namespace std;
using std::setprecision;


//The class Package is the base class for derived classes TwoDayPackage and OverNightPackage
  
class Package //begins class Package  
{  
public:  
    Package(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double = 0.0, double = 0.0, double = 0.0); //constructor  

    //set and get functions for sender  
    void setSenderName(const string &);  
    string getSenderName() const;  
  
    void setSenderAddress(const string &);  
    string getSenderAddress() const;  
      
    void setSenderCity(const string &);  
    string getSenderCity() const;  
  
    void setSenderState(const string &);  
    string getSenderState() const;  
  
    void setSenderZip(const string &);  
    string getSenderZip() const;  
      
    //set and get functions for recipient  
    void setRecipientName(const string &);    
    string getRecipientName() const;    
  
    void setRecipientAddress(const string &);    
    string getRecipientAddress() const;    
  
    void setRecipientCity(const string &);    
    string getRecipientCity() const;    
  
    void setRecipientState(const string &);    
    string getRecipientState() const;  
  
    void setRecipientZip(const string &);    
    string getRecipientZip() const;  
      
    void setShipWeight(double);  
    double getShipWeight() const;  

    void setShipRate(double);  
    double getShipRate() const;

    double calculateCost() const;
  
private:  
    string senderName;  
    string senderAddress;  
    string senderCity;  
    string senderState;  
    string senderZip;  
    string recipientName;  
    string recipientAddress;  
    string recipientCity;  
    string recipientState;  
    string recipientZip;  
    double shipWeight;  
    double shipRate;  
};

Package::Package(const string &sname, const string &saddress, const string &scity, const string &sstate, const string &szip, const string &rname, const string &raddress, const string &rcity, const string &rstate, const string &rzip, double weight, double rate, double calculateCost)  
{  
    senderName = sname;  
    senderAddress = saddress;  
    senderCity = scity;  
    senderState = sstate;  
    senderZip = szip;  
    recipientName = rname;  
    recipientAddress = raddress;  
    recipientCity = rcity;  
    recipientState = rstate;  
    recipientZip = rzip;  
    setShipWeight(weight);  
    setShipRate(rate);
    calculateCost;
}  
  
void Package::setSenderName(const string &sname)  
{  
    senderName = sname;  
}  
  
string Package::getSenderName() const  
{  
    return senderName;  
}  
  
void Package::setSenderAddress(const string &saddress)  
{  
    senderAddress = saddress;  
}  
  
string Package::getSenderAddress() const  
{  
    return senderAddress;  
}  
void Package::setSenderCity(const string &scity)  
{  
    senderCity = scity;  
}  
  
string Package::getSenderCity() const  
{  
    return senderCity;  
}  
  
void Package::setSenderState(const string &sstate)  
{  
    senderState = sstate;  
}  
  
string Package::getSenderState() const  
{  
    return senderState;  
}  
  
void Package::setSenderZip(const string &szip)  
{  
    senderZip = szip;  
}  
  
string Package::getSenderZip() const  
{  
    return senderZip;  
}  
  
void Package::setRecipientName(const string &rname)  
{  
    recipientName = rname;  
}  
  
string Package::getRecipientName() const  
{  
    return recipientName;  
}  
  
void Package::setRecipientAddress(const string &raddress)  
{  
    recipientAddress = raddress;  
}  
  
string Package::getRecipientAddress() const  
{  
    return recipientAddress;  
}  
  
void Package::setRecipientCity(const string &rcity)  
{  
    recipientCity = rcity;  
}  
  
string Package::getRecipientCity() const  
{  
    return recipientCity;  
}  
  
void Package::setRecipientState(const string &rstate)  
{  
    recipientState = rstate;  
}  
  
string Package::getRecipientState() const  
{  
    return recipientState;  
}  
void Package::setRecipientZip(const string &rzip)  
{  
    recipientZip = rzip;  
}  
  
string Package::getRecipientZip() const  
{  
    return recipientZip;  
}  
  
void Package::setShipWeight(double weight)  
{  
    shipWeight = (weight < 0.0 ) ? 0.0 : weight;  
}  
double Package::getShipWeight() const  
{  
    return shipWeight;  
}  
void Package::setShipRate(double rate)  
{  
    shipRate = ( rate < 0.0) ? 0.0 : rate;  
}  
  
double Package::getShipRate() const  
{  
    return shipRate;  
}  
  
//double Package::calculateCost() const  
//{    
//    return shipWeight * shipRate;  
//}  




//The class TwoDayPackage is the first derived class from class Package
  
class TwoDayPackage : public Package  
{  
public:  
    TwoDayPackage(const string &, const string &, const string &, const string &, const string &, const string &,  
      const string &, const string &, const string &, const string &, double = 0.0, double = 0.0); //constructor  
      
    void setFlatFee(double);  
    double getFlatFee() const;  
    double calculateCost() const;  
  
private:  
    double flatFee;  
};  

TwoDayPackage::TwoDayPackage(
        const string &sname, const string &saddress, const string &scity, const string &sstate,
        const string &szip, const string &rname, const string &raddress, const string &rcity,
        const string &rstate, const string &rzip, double shipWeight, double shipRate)
        //explicitly call base-class constructor
        : Package(sname, saddress, scity, sstate, szip, rname, raddress, rcity, rstate, rzip, shipWeight, shipRate)
{
    setFlatFee(flatFee); //validate and store flatFee
}

//set flatFee
void TwoDayPackage::setFlatFee(double fee)
{
    flatFee = (fee < 0.0) ? 0.0 : fee;
}//end function setFlatFee

//return flatFee
double TwoDayPackage::getFlatFee() const
{
    return flatFee;
}//end function getFlatFee

//calculate total cost
double TwoDayPackage::calculateCost() const
{
    return flatFee + (getShipWeight() * getShipRate());
}

  
  
//The class OverNightPackage is the second derived class from class Package
  
class OverNightPackage : public Package  
{  
public:  
    OverNightPackage(const string &, const string &, const string &, const string &, const string &, const string &,
      const string &, const string &, const string &, const string &, double = 0.0, double = 0.0, double = 0.0); //constructor  

        void setFee(double);  
        double getFee() const;  
        double calculateCost() const;  
  
private:  
    double fee;  
};  

OverNightPackage::OverNightPackage(
        const string &sname, const string &saddress, const string &scity, const string &sstate,
        const string &szip, const string &rname, const string &raddress, const string &rcity,
        const string &rstate, const string &rzip, double shipWeight, double shipRate)
        //explicitly call base-class constructor
        : Package(sname, saddress, scity, sstate, szip, rname, raddress, rcity, rstate, rzip, shipWeight, shipRate)
{
    setFee(fee); //validate and store fee
}

//set fee
void OverNightPackage::setFee(double fee)
{
    setFee = (fee < 0.0) ? 0.0 : fee;
}//end function setFee

//return fee
double OverNightPackage::getFee() const
{
    return fee;
}//end function getFee

//calculate total cost
double OverNightPackage::calculateCost() const
{
    return fee + (getShipWeight() * getShipRate());
}

//Test File
  
int main()  
{  
    OverNightPackage box("John Doe", "789 Fire Street", "Hell", "MI", "48169", "Jane Doe", "987 Leg Sun Crossing", "Intercourse", "PA", "17534", 10.00, 1.50, .85);  
      
    TwoDayPackage parcel("John Doe", "789 Fire Street", "Hell", "MI", "48169", "Jane Doe", "987 Leg Sun Crossing", "Intercourse", "PA", "17534", 15.00, 1.05, 5.00);  
  
    cout << fixed << setprecision(2);  
      
    cout << "To ship a box with overnight delivery:\n"
         << "\nThe sender    " << box.getSenderName()  
         << "\n              " << box.getSenderAddress()
         << "\n              " << box.getSenderCity() << ", " << box.getSenderState() << "  " << box.getSenderZip()
      
  
         << "\nThe recipient   " << box.getRecipientName()  
         << "\n                " << box.getRecipientAddress()
         << "\n                " << box.getRecipientCity() << ", " << box.getRecipientState() << "  " << box.getRecipientZip()  
         << "\nThe cost is   $ " << box.calculateCost()
      
      
         << "\n\n\n\nTo ship a parcel with 2 day delivery:\n"
         << "\nThe sender    " << parcel.getSenderName()  
         << "\n              " << parcel.getSenderAddress()
         << "\n              " << parcel.getSenderCity() << ", " << parcel.getSenderState() << "  " << parcel.getSenderZip()  
      
  
         << "\nThe recipient " << parcel.getRecipientName()
         << "\n              " << parcel.getRecipientAddress()
         << "\n              " << parcel.getRecipientCity() << ", " << parcel.getRecipientState() << "  " << parcel.getRecipientZip()
         << "\nThe cost is   $ "<< parcel.calculateCost() << endl;  
  
   _getch();

}
User is offlineProfile CardPM

Go to the top of the page

skaoth
post 20 Jul, 2008 - 12:33 AM
Post #4


D.I.C Regular

Group Icon
Joined: 7 Nov, 2007
Posts: 333



Thanked 8 times

Dream Kudos: 100
My Contributions


So here is what I've found. Note: I didn't run the code just worked on the compiler errors.

1) The OverNightPackage class constructor is different between definition and implementation. There are 3 doubles at the end of the constructor definition but only 2 in the implmentation.

2)
CODE

//set fee
void OverNightPackage::setFee(double fee)
{
    //setFee = (fee < 0.0) ? 0.0 : fee;
    // should be this
    this->fee = (fee < 0.0) ? 0.0 : fee;
}//end function setFee


3) In main(), when you create this TwoDayPackage parcel make sure you only pass in 12 parameters, it looks like your passing in 13

User is offlineProfile CardPM

Go to the top of the page

chaoticabyss99
post 20 Jul, 2008 - 10:43 AM
Post #5


D.I.C Head

**
Joined: 14 Jun, 2008
Posts: 90


My Contributions


QUOTE(skaoth @ 20 Jul, 2008 - 12:33 AM) *

So here is what I've found. Note: I didn't run the code just worked on the compiler errors.

1) The OverNightPackage class constructor is different between definition and implementation. There are 3 doubles at the end of the constructor definition but only 2 in the implmentation.

2)
CODE

//set fee
void OverNightPackage::setFee(double fee)
{
    //setFee = (fee < 0.0) ? 0.0 : fee;
    // should be this
    this->fee = (fee < 0.0) ? 0.0 : fee;
}//end function setFee


3) In main(), when you create this TwoDayPackage parcel make sure you only pass in 12 parameters, it looks like your passing in 13


Excellent!! Thanks for your input Skaoth!!
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 10/7/08 08:38PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month