On May 9, 10:42 am, saneman <d...@[EMAIL PROTECTED]
> wrote:
> hurcan solter wrote:
> thanks! Yes it was a bit late :-) I am wondering why the baseclass
> should be declared as abstract.
It doesn't have to be.
> I have tried to change it to:
>
> class geometry_type
> {
> public:
> virtual void haps(geometry_type* other)
> {
> other->collideWith(this);
And what should this call? Function overload resolution only
concerns static types.
> }
> virtual void collideWith(Box* other)
> {
> std::cout << "Box collision" << std::endl;
> }
> virtual void collideWith(Sphere* other)
> {
> std::cout << "Sphere collision" << std::endl;
> }
> // virtual void haps(geometry_type* other)=3D0;
> // virtual void collideWith(Box* other)=3D0;
> // virtual void collideWith(Sphere* other) =3D 0;
> };
> But then I get:
>
> test2.cpp: In member function ?virtual void
> geometry_type::haps(geometry_type*)?:
> test2.cpp:16: error: no matching function for call to
> ?geometry_type::collideWith(geometry_type* const)?
> test2.cpp:19: note: candidates are: virtual void
> geometry_type::collideWith(Box*)
> test2.cpp:24: note: virtual void
> geometry_type::collideWith(Sphere*)
> Is there some rule that the baseclass must be abstract?
No. But there is a rule that when you call a function, one of
the function found with name lookup must be callable with the
static types of your arguments.
Think about it for a moment. What you're asking for is
basically double dispatch. Or at least, dispatch on the dynamic
type of an argument, not on the object the function is called
on.
--
James Kanze (GABI Software) email:james.kanze@[EMAIL PROTECTED]
en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34


|