Nothing wrong with my write function, think error is related to code above it!Code:Contract::Contract(): issued( Date::getCurrentTime() );// is this semicolon necessary? // Display the customer's contract, or save it to text file void Contract::Write(ostream& out, bool isScreen) { } // : error C2062: type 'void' unexpected // : error C2630: ';' found in what should be a comma-separated list // : error C2065: 'isScreen' : undeclared identifier // : error C2065: 'out' : undeclared identifier // : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
You should havein your Contract constructor, instead of the semicolon. Even if you don't do anything in the constructor, it does need a (empty) function bodyCode:{}
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
It is "this" object. e.g.
Most of the time, you don't need the this pointer, but it is passed to all non-static member functions, including constructor.Code:class X { public: X(); void foo(); private: int x; } void X::foo() { x = 7; // the above is short for this->x = 7; }
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I agree with this. An object that has "nonsense" in it because the constructor placed it there is pretty meaningless.
On a different not, more towards the contract of rentals: You may want to actually fill in the date of expected return, even if that's not the actual return date. You can then correct it when the car is actually returned.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Anything wrong with this overloading
ts is enum type....Code:Car::TankStatus operator=(int number, Car::TankStatus ts) { return ts = number; } //: error C2801: 'operator =' must be a non-static member
I believe the left-hand side of operator= must be a user-defined type (you have int) because it can only be overloaded as a non-static member.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
The bold part is what would be on the left of the assignment operator.Code:Car::TankStatus operator=(int number, Car::TankStatus ts)
But anyway, it seems that you can't overload operator= for enum types anyway since it can only be overloaded as non-static member function.
Come to think of it, how would you implement the assignment of the actual enum value, if operator= is not available (since you are in the process of defining it)?
You can already assign enum to int and to enum, and you can assign int to enum with the help of a cast (but be careful with that since the int may not contain one of the enumerated values).
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Operator = must be a member of the class to which it is defined to work with.
As thus, operator = does not work for enums, only classes.
Either way, you should not assign an int to an enum; you're essentially circumventing the whole C++ type safety.
You can certainly make "global" operator=() operator, that takes two arbitrary classes [that you have some idea of how you would convert to the left-hand side type].
The reason, I believe, for this operator is the need to serialize the data to file. If it was stored from the enum on the file, then it should be safe to read back. We could add checks in the operator to ensure that's the case.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
But how?You can certainly make "global" operator=() operator, that takes two arbitrary classes [that you have some idea of how you would convert to the left-hand side type].
Code:struct X {}; struct Y {}; X& operator= (X& x, const Y&) //X& operator=(X&, const Y&)' must be a nonstatic member function { return x; }
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Searching the web, I can't actually find it, nor in Stroustrup (but the index is a bit hard to use in Stroustrup - doesn't always list what you want).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.