 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Stefano Zaglio Guest
|
Posted: Thu Oct 23, 2003 10:43 pm Post subject: overloading or casting? A simple problem. |
|
|
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
|
Posted: Fri Oct 24, 2003 7:13 pm Post subject: Re: overloading or casting? A simple problem. |
|
|
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 |
|
 |
|
|
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
|
|