Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > operator int()
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 43296 of 48417
Post > Topic >>

operator int()

by onkar <onkar.n.m@[EMAIL PROTECTED] > Feb 13, 2008 at 11:56 AM

SomeClass{
               public:
                       int i;
                       SomeClass(int j):i(j){};
                       operator int(){
                                       return this->i;
                       }
              // some functions (all of them public) and
constructors ??

};
int main(void){
           SomeClass s(10);
           int i=s;
           cout<<i<<endl;
           return 0;
}

I am not able to understand why this is printing 10 ??? How is
"operator int()" function called ??
 




 7 Posts in Topic:
operator int()
onkar <onkar.n.m@[EMAI  2008-02-13 11:56:35 
Re: operator int()
Christopher <cpisz@[EM  2008-02-13 12:00:04 
Re: operator int()
"Victor Bazarov"  2008-02-13 15:48:01 
Re: operator int()
Rolf Magnus <ramagnus@  2008-02-13 21:05:39 
Re: operator int()
Christopher <cpisz@[EM  2008-02-13 18:06:50 
Re: operator int()
thomas <FreshThomas@[E  2008-02-13 21:29:07 
Re: operator int()
Christopher <cpisz@[EM  2008-02-14 08:38:46 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 10:36:18 CST 2008.