Created
March 22, 2019 13:14
-
-
Save kateolenya/47ef8503c41d4ef491804821714db5e9 to your computer and use it in GitHub Desktop.
Example of pure abstract class in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Device { | |
public: | |
virtual void turn_on() = 0; | |
}; | |
class Computer { | |
public: | |
void turn_on() { | |
cout << "Welcome to Windows 95" << endl; | |
} | |
}; | |
class Laptop: public Device { | |
public: | |
void turn_on() { | |
cout << "Welcome to Windows XP" << endl; | |
} | |
}; | |
int main() { | |
Computer my_computer; | |
Laptop my_laptop; | |
// Device my_device; | |
// will cause compile time error | |
my_computer.turn_on(); | |
my_laptop.turn_on(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment