0

Related question: Using "super" in C++

I examined the source code for OpenSteer and found the following code for defining properties of vehicles. The requirement is Super have too be inherited from an interface class AbstractVehicle.

template <class Super>
class SteerLibraryMixin : public Super { ... }

template <class Super>
class AnnotationMixin: public Super { ... }

template <class Super>
class LocalSpaceMixin: public Super { ... }

With these I could define a SimpleVehicle with all properties:

// SimpleVehicle_1 adds concrete LocalSpace methods to AbstractVehicle
typedef LocalSpaceMixin<AbstractVehicle> SimpleVehicle_1;


// SimpleVehicle_2 adds concrete annotation methods to SimpleVehicle_1
typedef AnnotationMixin<SimpleVehicle_1> SimpleVehicle_2;


// SimpleVehicle_3 adds concrete steering methods to SimpleVehicle_2
typedef SteerLibraryMixin<SimpleVehicle_2> SimpleVehicle_3;


// SimpleVehicle adds concrete vehicle methods to SimpleVehicle_3
class SimpleVehicle : public SimpleVehicle_3 { ... }

Or just with one of the properties:

class SimpleVehicle : public LocalSpaceMixin<AbstractVehicle> { ... }

This was pretty smart, here I could choose what properties my vehicles should have but when I tried to compile it it didn't work!

Compiler errors:

SteerLibrary.hpp||In member function Vec2D SteerLibrary<Super>::SteerForWander(float)':|
SteerLibrary.hpp|41|error: there are no arguments toGetMaxSpeed' that depend on a template parameter, so a declaration of GetMaxSpeed' must be available|
SteerLibrary.hpp|41|error: (if you use-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)|
SteerLibrary.hpp|42|error: there are no arguments to GetVel' that depend on a template parameter, so a declaration ofGetVel' must be available|

Here I'm trying to access my AbstractVehicle member function 'GetMaxSpeed' and 'GetVel'. With '-fpermissive' it compiles and work but it issues a warning for every member function and with good reason - one could pretty easily inherit from a non AbstractVehicle with none of these functions!

Now for my question: Is this a better way to handle this? I tried with the typedef method like the link above but it didn't work at all.

Community
  • 1
  • 1
Jonas
  • 1,532
  • 3
  • 16
  • 20

1 Answers1

4

I think that doing:

this->GetMaxSpeed()

will solve your problem. Also You could do:

SimpleVehicle::GetMaxSpeed()

both of these explicitly say where the function is coming from.

Evan Teran
  • 87,561
  • 32
  • 179
  • 238