[net.lang.c++] Casting into classes with constructors, a bug?

crowl@rochester.ARPA (08/13/86)

From: Lawrence Crowl  <crowl>

I am trying to define a class with type cast operator to another class.
This other class has a constructor defined.  When I invoke the cast on
the first class, the compiler (1.0) does not seem to recognize the cast
operator and insists on a parameter appropriate for the constructor.
Is what I am trying to do correct?  If it is correct, is this bug fixed
in version 1.1?  The code and error messages are below:

     1    class C
     2        {  
     3        int i ;
     4    public:
     5        C( int a ) { i = a ; }
     6        operator int( ) { return i ; }
     7        } ;
     8    
     9    class K
    10        {  
    11        int i ;
    12    public:
    13        K( int a ) { i = a ; }
    14        K( C c ) { i = int( c ) ; }
    15        operator C( ) { return i ; }
    16        } ;
    17    
    18    void main( )
    19        {
    20        C c( 1 ) ;
    21        K k1( 2 ) ;
    22        K k2( c ) ;
    23        int i1 = int( c ) ;
    24        int i2 = int( C( k1 ) ) ;
    25        }

"cast_bug.c", line 25: error:  struct K  operand for =
"cast_bug.c", line 25: error: bad argument 1 type for C::C(): K  
                              ( int  expected)

Any help appreciated.

--
  Lawrence Crowl		716-275-5766	University of Rochester
			crowl@rochester.arpa	Computer Science Department
 ...!{allegra,decvax,seismo}!rochester!crowl	Rochester, New York,  14627