This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Class casting


>>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());


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]