Skip to content

Instantly share code, notes, and snippets.

@kateolenya
Created March 22, 2019 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kateolenya/47ef8503c41d4ef491804821714db5e9 to your computer and use it in GitHub Desktop.
Save kateolenya/47ef8503c41d4ef491804821714db5e9 to your computer and use it in GitHub Desktop.
Example of pure abstract class in C++
#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