Board index » cppbuilder » Re: New type apear as a TColor ?
Chris Uzdavinis (TeamB)
![]() CBuilder Developer |
Re: New type apear as a TColor ?2007-12-11 09:43:30 PM cppbuilder92 Matthias Pätzold < XXXX@XXXXX.COM >writes: Quote>>TColor TAjColor::operator TColor() ^^^^^^ | | remove It's called "operator TColor()" which already says what type it returns, so you're not supposed to specify a return type in addition. Imagine the confusion if the following was allowed? class x { public: long operator int() const; // invalid }; What does operator int() return? A long??? No, operator int() must return an int, and does not require (or allow) an explicit return type: class x { public: operator int() const; // correct }; It would be redundant to be forced to say: class x { public: int operator int(); // invalid, redundant }; So they just drop the return type for conversion operators. I do strongly caution AGAINST using conversion operators except in very, very specific cases where it can be justified. These do tend to open the door to surprises and incorrect usages that silently compile and are a monster to debug. -- Chris (TeamB); |