| A C++ class that 'implements the interface' and uses the resulting class. | Lecture 4 - slide 9 : 24 Program 3 |
// An 'implementation' of the 'interface-like' abstract class in C++
#include <iostream>
enum GameObjectMedium {Paper, Plastic, Electronic};
class IGameObject{
public:
virtual int getGameValue() = 0;
virtual GameObjectMedium getMedium() = 0;
};
class GameObject: public IGameObject{
public:
int getGameValue(){
return 1;
}
virtual GameObjectMedium getMedium(){
return Electronic;
}
};
int main(){
IGameObject *ig = new GameObject();
std::cout << ig->getGameValue() << std::endl; // 1
std::cout << ig->getMedium() << std::endl; // 2
}