class declaration fails
Nov 29, 2019 at 1:15pm
What's wrong with the 'Subject' class declaration?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
enum class Type { Ground, Enemy, Boulder, Friend };
template<typename T>
class Object
{
public:
Object( const T & t = T{}, const Type tp = Type::Ground )
: mTexture(t), mType{tp}, mWalkable{true}
{}
Object() = default;
virtual ~Object() = default;
T & texture () { return mTexture; }
const T & texture () const { return mTexture; }
void texture (const T & texture) { mTexture = texture; }
bool operator==( const Object<T> & other) const
{ return mTexture == other.mTexture; }
bool isWalkable() const { return mWalkable; }
Type type() const { return mType; }
protected:
Type mType;
T mTexture;
bool mWalkable;
};
template<typename T>
class Subject : public Object
{
public:
Subject( const T & t = T{}, const Type tp = Type::Enemy
, int health = 0, int power = 0)
: Object<T>{t,tp}, mHealth{health}, mPower{power}
{}
int health() const { return mHealth; }
int power() const { return mPower; }
void health( int h) { mHealth = h; }
void power( int p) { mPower = p; }
protected:
int mHealth;
int mPower;
};
int main(){}
|
|
27:1: error: expected class-name before '{' token
|
Nov 29, 2019 at 1:33pm
Fond the error, line 26 needs to be:
|
class Subject : public Object<T>
|
Topic archived. No new replies allowed.