Skip to content

Instantly share code, notes, and snippets.

View kateolenya's full-sized avatar

Kateryna kateolenya

View GitHub Profile
@kateolenya
kateolenya / virtual_inheritance.cpp
Last active March 28, 2019 10:26
Example usage of keyword 'virtual' in C++
#include <iostream>
using namespace std;
class Device {
public:
Device() {
cout << "Device constructor called" << endl;
}
void turn_on() {
cout << "Device is on." << endl;
@kateolenya
kateolenya / multiple_inheritance.cpp
Last active March 29, 2019 11:24
Example of multiple inheritance in C++
#include <iostream>
using namespace std;
class Computer {
public:
void turn_on() {
cout << "Welcome to Windows 95" << endl;
}
};
@kateolenya
kateolenya / pure_abstract.cpp
Created March 22, 2019 13:14
Example of pure abstract class in C++
#include <iostream>
using namespace std;
class Device {
public:
virtual void turn_on() = 0;
};
class Computer {
public:
@kateolenya
kateolenya / base.c
Created March 25, 2019 15:02
Inheritance in C, struct as pure superset of another struct
#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 / main.c
Created March 25, 2019 15:03
Inheritance in C, short version of struct as pure superset of another struct
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Device {
int serial_number;
int sizeof_memory;
};
void print_values( struct Device * some_device ) {
#include <iostream>
using namespace std;
class Device {
public:
Device() {
cout << "Device constructor called" << endl;
}
};
#include <iostream>
using namespace std;
class Computer {
private:
void turn_on() {
cout << "Computer is on." << endl;
}
};
#include <iostream>
using namespace std;
class Device {
public:
void turn_on() {
cout << "Device is on." << endl;
}
virtual void say_hello() = 0;
};
#include <iostream>
using namespace std;
class Device {
public:
virtual void turn_on() = 0;
};
class Laptop: public Device {
public:
@kateolenya
kateolenya / overloaded_function.cpp
Last active April 26, 2019 09:57
Example of overloaded function in C++
#include <iostream>
using namespace std;
void custom_add(int a, int b) {
cout << "Int result = " << (a + b) << endl;
}
void custom_add(int a, int b, int c) {
cout << "Triple int result = " << (a + b + c) << endl;
}