C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

overloading or casting? A simple problem.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Stefano Zaglio
Guest





PostPosted: Thu Oct 23, 2003 10:43 pm    Post subject: overloading or casting? A simple problem. Reply with quote



I need simply this:

{
X status; // X is a class of only one int
status = 0;
status |= X::FLAG;
}

I want use "status" as an integer without do overloading of all operators
or build 2 function for each flag(set/reset) or 1 function with bool param.
(1) I cannot inherit X from int.
(2) I'm not able (or it cannot) build an autocasting X to int.

What about (2)?

Thanks
Stefano Z.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Erik Max Francis
Guest





PostPosted: Fri Oct 24, 2003 7:13 pm    Post subject: Re: overloading or casting? A simple problem. Reply with quote



Stefano Zaglio wrote:

Quote:
I want use "status" as an integer without do overloading of all
operators
or build 2 function for each flag(set/reset) or 1 function with bool
param.
(1) I cannot inherit X from int.

You'll need to overload each of the int-like operators you're interested
in supporting.

Quote:
(2) I'm not able (or it cannot) build an autocasting X to int.

What about (2)?

Define an operator int method:

class X
{
...
operator int () const { return ...; }
...
};

--
Erik Max Francis && [email]max (AT) alcyone (DOT) com[/email] && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ You and I / We've seen it all / Chasing our hearts' desire
__/ The Russian and Florence, _Chess_

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.