Class casting
Nathan Sidwell
nathan@codesourcery.com
Wed Jul 2 18:48:00 GMT 2003
Justin Miller wrote:
> Interestingly enough, if you did this:
>
> int main() {
> B b;
> C* c = new C(b);
> }
>
> It will compile and work as expected. The constructor wants an A, a B is
> an A, so everything is fine.
>
> Why one needs to declare the B first, rather than instantiating the
> temporary as in the code below, I have no idea. Can anyone shed some
> light on this?
class C{
public:
C(A& a) : initialize....{do Stuff;}
The 'B ()' part of 'C (B ())' cannot bind to a non-const reference.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
More information about the Gcc-help
mailing list