Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Typecasting operator on simple types vs. classes
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Nikolai Borissov, post: 1462468"] Nicolay Korslund wrote: There is a rule that in a conversion sequence only one use-defined conversion operator is allowed. My guess is that the rule covers overloaded operators too. t1[0] works because there is only one use-defined conversion is involved : operator mytype () {return i;} It returns object of double* type for which built-in [] operator is defined. t2[0], however, casts through the above user-defined conversion to Test2 type, which, in turn, has only use-defined [] operator. Of course, when you remove one of user-defined operators from implicit sequence by explicit typecasting, everything works: ((Test2)t2)[0] I would suggest adding [] operator to the *Test* class, like this int operator[](int ind) {return i[ind];} Then you don't have to think about typecasting. Nikolai Borissov [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Typecasting operator on simple types vs. classes
Top