"overloaded cast operator" and "operator const"



 DEVELOP > c-Plus-Plus > "overloaded cast operator" and "operator const"

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "John Goche"
Date: 04 Sep 2006 05:03:15 AM
Object: "overloaded cast operator" and "operator const"
Hello,
Could anyone please provide with some information on the
C++ overloaded cast operator and in which circumstances
this might be useful? I have consulted several references
but found no information on the uses of this operator.
Thanks,
JG
.

User: "Frederick Gotham"

Title: Re: "overloaded cast operator" and "operator const" 04 Sep 2006 09:48:12 AM
John Goche posted:


Hello,

Could anyone please provide with some information on the
C++ overloaded cast operator and in which circumstances
this might be useful? I have consulted several references
but found no information on the uses of this operator.

Thanks,

JG

Maybe something like:
class InputStream {
private:
bool success_last_write;
public:
InputStream &operator>>(int);
operator bool()
{
return success_last_write;
}
};
int main()
{
InputStream is;
int i;
if(is >> i)
{
/* Do something */
}
}
--
Frederick Gotham
.

User: "Rolf Magnus"

Title: Re: "overloaded cast operator" and "operator const" 04 Sep 2006 05:49:15 AM
John Goche wrote:


Hello,

Could anyone please provide with some information on the
C++ overloaded cast operator

It's a conversion operator. A "cast operator" doesn't exist.

and in which circumstances this might be useful?

It can be useful if you want to provide a conversion from your class into a
built-in type or another class that you can't change. In any other case,
you should prefer a conversion constructor.
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER