#### Archived

This topic is now archived and is closed to further replies.

# operator CString( );

This topic is 5493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have come across this in a MFC based prog that i''m working on and i cannot find what it means in any of my books. It looks like the CString class is being overloaded? Can somebody please explain what is happening.. it appears in a class definition as public. Thanks for the help!

##### Share on other sites
An operator type(), where ''type'' represents any type, is a casting operator. For instance, if class Banana defines operator Fish(), you will be able to cast a Banana to a Fish.

##### Share on other sites
To clarify what Miserable said, this is an implicit typecast operator. It means that the compiler is free to use it to cast to the target type whenever it makes sense, not just when you explicitly invoke the cast.

Single-argument constructors act as explicit typecast operators.

How appropriate. You fight like a cow.

##### Share on other sites
Wooooww thats making me dizzy!

So is anything being overloaded... i''m not following?

operator CString(); is a an implict typecast operator???

Under what part of C++ should i be lloking for an explantion...

Thanks

##### Share on other sites
quote:
Original post by Sneftel
Single-argument constructors act as explicit typecast operators.

I thought it was only if they were marked explicit .

Example for Woody:
void func(CString s);int main(){ MyClass c; // defines operator CString func(c);   // method operator CString called for implicit conversion }

Implicit conversion is generally pretty evil most of the time because you don't see it happening (hence "implicit"). Thats why you don't see it in many standard library classes.

[edited by - antareus on July 2, 2003 6:18:47 PM]

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 36
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631703
• Total Posts
3001814
×