It sounds to me like you should just drop the virtual function declaration in the abstract "A" class (or make it non-virtual). It serves no purpose other than trying to enforce your design on the subclasses. Since you require the foo() function to take a parameter of the subclass type, only a B can foo a B, and only a C can foo a C. Let us not use complex language constructs (templates for example) just to allow the compiler to check that you're following your own convention. Put a comment in the base class that defines this requirement on subclasses and call it a day. OTOH, if generic code is going to tell an X to foo another X (somehow knowing they are the same type) this might not work. Hmmmm. I think another option is to declare A:foo(A p1) and then have the B class explicitly cast the parameter p1 to a B inside B:foo when using the B-specific functionality of the parameter. I don't know how to do templates, so this is what I might do until it got too ugly.
Hope that helps, Paul On Sat, 2005-01-15 at 15:12 +0100, Christian Mayer wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, > > can someone help me to solve thise problem: > > Imagine I've got this class hierachy: > > class A > { > virtual bool foo( A bar ) = 0; > } > > class B : A > { > bool foo( B bar ) > { > ... > } > .... > } > > int main( void ) > { > B foobar; > } > > this won't compile as my class B is still abstract as I didn't provide a > "bool foo( A bar )" member. > > But I only want class A to be an interface that tells everybody what to > expect from it's derivated classes. And one of these things is, that > every child must have a member that is called "foo" and has one > parameter of the type of the child itself. > > How do I achieve that? > > > The only workaround I can come up with is, that I have: > class B > { > friend bool foo( class B, class B ); > } > > bool foo( class B bar1, class B bar2 ) > { > ... > } > > I this doesn't guarantee me, that every child of A must have a foo > function... > > Thanks, > Christian _______________________________________________ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d