🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by crowl Wed, 13 Aug 1986 02:23
Casting into classes with constructors, a bug?
#280
Author: crowl
Date: Wed, 13 Aug 1986 02:23
45 lines
1971 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads