#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    21
    Rep Power
    0

    Operator overloading,initization, Print() in header file


    I'm currently writing a header file for a Car class. But The problem is I don't know how to initialized in the Car class and use the copy constructor in the header file. Also, this header file requires a operator function. When I compile it, I have a syntax errors for those two operator function. For the Print() method, I have to use it for display the mantfacturere, model, year, total manufacture, total kilometers travelled and the amount of fuel costs, total number of services and fuel economy with print method. Can anyone please take a look at my code and help me fixing some of the mistakes in the header file?

    Thank you

    PHP Code:
    #ifndef CAR_H
    #define CAR_H
    #ifndef LEN
    #define LEN 25

    class Car
    {    
           private:
               
    char name[LEN]; 
               
    char model[LEN]; 
               
    int year;
        
           public:
                
    Car();
                
    Car(char *mchar *nint y);
                
    Car(const Car &source);              //copy constructor
                
    const Car operator +(const Journeymeter) const;
                const 
    Car operator +(const FuelPurchaseamount) const;
                
    void print(void) const;        
                ~
    Car();
    };
    #endif 
    Last edited by Tozilla; March 26th, 2003 at 10:04 PM.
  2. #2
  3. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12

    Re: Operator overloading,initization, Print() in header file


    PHP Code:
    const Car operator +(const Journeymeter) const;
    const 
    Car operator +(const FuelPurchaseamount) const; 
    Should be:
    PHP Code:
    const operator +(const Journeymeter) const;
    const 
    operator +(const FuelPurchaseamount) const; 
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    You sure about that Jason Doucette?
  6. #4
  7. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12

    Re: Re: Operator overloading,initization, Print() in header file


    You're right, I am wrong.

    I thought he was using the class name and forgetting the scope resolution operator ::, which is only needed in the definition outside of the class. I didn't look at it carefully enough. The only thing wrong with his code is the const at the start. His code should be:

    Code:
    Car operator +(const Journey& meter) const;
    Car operator +(const FuelPurchase& amount) const;

IMN logo majestic logo threadwatch logo seochat tools logo