|
-
Mar 26th, 2003, 02:44 PM
#1
Thread Starter
New Member
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 *m, char *n, int y);
Car(const Car &source); //copy constructor
const Car operator +(const Journey& meter) const;
const Car operator +(const FuelPurchase& amount) const;
void print(void) const;
~Car();
};
#endif
Last edited by Tozilla; Mar 26th, 2003 at 10:06 PM.
-
Mar 27th, 2003, 03:19 PM
#2
#ifndef LEN
#define LEN 25
Missing #endif. Also, #defines for constants is for C, in C++ you should write
const int LEN = 25;
which gives you type checking.
Second, use the std::string class for the strings if you are allowed to.
Third, the return type of the + operators shouldn't be const.
That should be all.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|