| virtual-member-functions/interface-like-class-and-use.cc - A C++ class that 'implements the interface' and uses the resulting class. | Lecture 5 - slide 11 : 40 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() override{
return 1;
}
GameObjectMedium getMedium() override{
return Electronic;
}
};
int main(){
IGameObject *ig = new GameObject(); // Polymorphic
std::cout << ig->getGameValue() << std::endl; // 1
std::cout << ig->getMedium() << std::endl; // 2
}