www.digitalmars.com         C & C++   DMDScript  

c++ - enum to int conversion (bug?)

reply Arjan <Arjan_member pathlink.com> writes:
I don't know whether this is a bug or not, Comeau compiles it without a problem.

#include <stdio.h>



class  Bug3
{
public :
enum  Type
{
Type_ONE =   0x0001,
Type_TWO =   0x0002
};

public :
Bug3 () {}
bool              Set ( bool  _one, Type  _two = Type_ONE )
{
printf ( "Set ( bool _one = %b )\n", _one );

return ( true );
}

bool              Set ( int  _one = 0, Type  _two = Type_ONE )
{
printf ( "Set ( int  _one = %d )\n", _one );

return ( true );
}
};

int  main ( int  argc,  char  *argv [] )
{
Bug3  test;

test.Set ( true            , Bug3 :: Type_ONE );                  // this works
test.Set ( false           , Bug3 :: Type_ONE );                  // this works
test.Set ( 0               , Bug3 :: Type_TWO );                  // this works
test.Set ( 1               , Bug3 :: Type_TWO );                  // this works
test.Set ( Bug3 :: Type_ONE, Bug3 :: Type_TWO );                  // this does
NOT work
test.Set ( Bug3 :: Type_TWO, Bug3 :: Type_TWO );                  // this does
NOT work

return ( 0 );
}
Apr 02 2003
parent "KarL" <someone somewhere.org> writes:
Yep, this is a similar problem as the one I posted
before about the int <-> bool conversion problem.

"Arjan" <Arjan_member pathlink.com> wrote in message
news:b6ecdg$ulb$1 digitaldaemon.com...
 I don't know whether this is a bug or not, Comeau compiles it without a
problem.
 #include <stdio.h>



 class  Bug3
 {
 public :
 enum  Type
 {
 Type_ONE =   0x0001,
 Type_TWO =   0x0002
 };

 public :
 Bug3 () {}
 bool              Set ( bool  _one, Type  _two = Type_ONE )
 {
 printf ( "Set ( bool _one = %b )\n", _one );

 return ( true );
 }

 bool              Set ( int  _one = 0, Type  _two = Type_ONE )
 {
 printf ( "Set ( int  _one = %d )\n", _one );

 return ( true );
 }
 };

 int  main ( int  argc,  char  *argv [] )
 {
 Bug3  test;

 test.Set ( true            , Bug3 :: Type_ONE );                  // this
works
 test.Set ( false           , Bug3 :: Type_ONE );                  // this
works
 test.Set ( 0               , Bug3 :: Type_TWO );                  // this
works
 test.Set ( 1               , Bug3 :: Type_TWO );                  // this
works
 test.Set ( Bug3 :: Type_ONE, Bug3 :: Type_TWO );                  // this
does
 NOT work
 test.Set ( Bug3 :: Type_TWO, Bug3 :: Type_TWO );                  // this
does
 NOT work

 return ( 0 );
 }
Apr 02 2003