This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Class casting
- From: Greg Davey <mailforroot at turbodiesel360 dot cjb dot net>
- To: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: 02 Jul 2003 21:35:59 -0400
- Subject: Re: Class casting
- References: <BB288579.9834%eljay@adobe.com>
>>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());