Skip to content

Instantly share code, notes, and snippets.

@kateolenya
Created March 28, 2019 12:55
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/cfa7dbcd9d16ca0bbff95e53d0a3dfcc to your computer and use it in GitHub Desktop.
Save kateolenya/cfa7dbcd9d16ca0bbff95e53d0a3dfcc to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class Device {
public:
void turn_on() {
cout << "Device is on." << endl;
}
virtual void say_hello() = 0;
};
class Laptop: public Device {
public:
void say_hello() {
cout << "Hello world!" << endl;
}
};
int main() {
Laptop Laptop_instance;
Laptop_instance.turn_on();
Laptop_instance.say_hello();
// Device Device_instance;
// will cause compile time error
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment