I am writing a Game & I have a interface called GameObject.
This game object is implemented by derived objects say planet , comet , asteroids etc. Now I need type_index of these objects in different functions.
To achieve this I define virtual function in GameObject & want to use template pattern with type of derived class . unfortunately I am getting error error: explicit specialization of non-template struct 'GameObjectImpl' template struct GameObjectImpl : GameObject ^
Below is the source code
struct GameObject
{
virtual ~GameObject() = default;
virtual type_index type() const = 0;
};
template <typename T> struct GameObjectImpl<T> : GameObject //error
{
type_index type() const override
{
return typeid(T);
}
};
struct Planet : GameObjectImpl<Planet>{};
struct Asteriod : GameObjectImpl<Asteriod>{};
Can you please let me know how to get rid of this error.Pl note i am learning template pattern so wants to use only template
Aucun commentaire:
Enregistrer un commentaire