Skip to content

Instantly share code, notes, and snippets.

Kateryna kateolenya

View GitHub Profile
View interface.cpp
#include <iostream>
using namespace std;
class Device {
public:
virtual void turn_on() = 0;
};
class Laptop: public Device {
public:
View abstract.cpp
#include <iostream>
using namespace std;
class Device {
public:
void turn_on() {
cout << "Device is on." << endl;
}
virtual void say_hello() = 0;
};
View simple_inh_pr.cpp
#include <iostream>
using namespace std;
class Computer {
private:
void turn_on() {
cout << "Computer is on." << endl;
}
};
View diamond_constructor.cpp
#include <iostream>
using namespace std;
class Device {
public:
Device() {
cout << "Device constructor called" << endl;
}
};
@kateolenya
kateolenya / main.c
Created Mar 25, 2019
Inheritance in C, short version of struct as pure superset of another struct
View main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Device {
int serial_number;
int sizeof_memory;
};
void print_values( struct Device * some_device ) {
@kateolenya
kateolenya / base.c
Created Mar 25, 2019
Inheritance in C, struct as pure superset of another struct
View base.c
#include "base.h"
#include <stdio.h>
struct Device {
int serial_number;
int sizeof_memory;
};
void print_values( struct Device * some_device ) {
printf("Serial number: %d, ", some_device->serial_number);
@kateolenya
kateolenya / pure_abstract.cpp
Created Mar 22, 2019
Example of pure abstract class in C++
View pure_abstract.cpp
#include <iostream>
using namespace std;
class Device {
public:
virtual void turn_on() = 0;
};
class Computer {
public:
@kateolenya
kateolenya / multiple_inheritance.cpp
Last active Mar 29, 2019
Example of multiple inheritance in C++
View multiple_inheritance.cpp
#include <iostream>
using namespace std;
class Computer {
public:
void turn_on() {
cout << "Welcome to Windows 95" << endl;
}
};
@kateolenya
kateolenya / virtual_inheritance.cpp
Last active Mar 28, 2019
Example usage of keyword 'virtual' in C++
View virtual_inheritance.cpp
#include <iostream>
using namespace std;
class Device {
public:
Device() {
cout << "Device constructor called" << endl;
}
void turn_on() {
cout << "Device is on." << endl;
@kateolenya
kateolenya / diamond_problem.cpp
Last active Mar 29, 2019
Example of diamond problem in C++
View diamond_problem.cpp
#include <iostream>
using namespace std;
class Device {
public:
void turn_on() {
cout << "Device is on." << endl;
}
};
You can’t perform that action at this time.