Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rochester!crowl From: crowl@rochester.ARPA Newsgroups: net.lang.c++ Subject: Casting into classes with constructors, a bug? Message-ID: <20105@rochester.ARPA> Date: Tue, 12-Aug-86 22:23:42 EDT Article-I.D.: rocheste.20105 Posted: Tue Aug 12 22:23:42 1986 Date-Received: Wed, 13-Aug-86 03:13:41 EDT Sender: crowl@rochester.ARPA Organization: U of Rochester, CS Dept., Rochester, NY Lines: 45 From: Lawrence 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