Class casting
Greg Davey
mailforroot@turbodiesel360.cjb.net
Thu Jul 3 01:36:00 GMT 2003
>>Hi Greg,
>>
>>Change it to...
>> C(const A& a) : initialize....{do Stuff;}
>>The const keyword is important. Temporaries are not allowed there,
>>otherwise. It's in the C++ language specification.
I had tried this before but ran into a couple problems:
1) I had a situation that needed the const refrence to be passed to the
base-class. For example:
C* c = new C(B(some_other_derived_class()));
and B's base class must be passed some_other_derived_class() in the
constructor. The compiler refused to pass the const reference.
2) I had to force the cast. i.e.
To instantiate the object the function call then had to become,
C* c = new C((const A&) B());
More information about the Gcc-help
mailing list