Re: Class casting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux