Re: child and parent class args
From: Rolf Magnus (ramagnus_at_t-online.de)
Date: Wed, 30 Mar 2005 12:14:47 +0200
David Sobey wrote:
> Here's some code:
> void SomeFunc(childClass arg);
> parentClass a;
> a=new childClass();
a is an object of type parentClass. You can't assign a pointer to it, which
is what new returns. Also, note that a is already a full-blown object. No
need to create another one with new.
I assume by parentClass, you mean a base class, and childClass is a class
derived from that base class. Then this won't work.
> this spits out an error, it can't convert an object of type parentClass to
It should give you more errors than that.
> Doesn't work for pointers either. Can anyone shed some light
> on how to get this working without casting?
It won't work with casting either. Ayway, what are you actually trying to
do? The above code doesn't make much sense. You can't just pass an object
of a base class to a function that expects an object of a class derived
from it, neither by value, nor by pointer or by reference. And casting is
not the solution.