Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.