Skip to content

Instantly share code, notes, and snippets.

Kateryna kateolenya

View GitHub Profile
@kateolenya
kateolenya / template_class_spec.cpp
Last active Apr 24, 2019
Example of specialized template class in C++
View template_class_spec.cpp
#include <iostream>
using namespace std;
template <class T>
class two_values {
T a, b;
public:
two_values (T first_arg, T second_arg) {
a = first_arg;
b = second_arg;
View template_function.cpp
#include <iostream>
using namespace std;
template <class T>
void custom_add (T a, T b) {
cout << "Template result = " << a + b << endl;
}
int main () {
@kateolenya
kateolenya / template_class.cpp
Last active Apr 24, 2019
Example of class template in C++
View template_class.cpp
#include <iostream>
using namespace std;
template <class T>
class two_values {
T a, b;
public:
two_values (T first_arg, T second_arg) {
a = first_arg;
b = second_arg;
@kateolenya
kateolenya / overloaded.cpp
Last active Apr 24, 2019
Example of overloaded function in C++
View overloaded.cpp
#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;
}
View diamond_constructor.cpp
#include <iostream>
using namespace std;
class Device {
public:
Device() {
cout << "Device constructor called" << 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;
}
};
@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 / constructor.cpp
Last active Mar 29, 2019
Process of calling inherited constructors and destructors in C++
View constructor.cpp
#include <iostream>
using namespace std;
class Device {
public:
// constructor
Device() {
cout << "Device constructor called" << endl;
}
// destructor
@kateolenya
kateolenya / basic_inheritance.cpp
Last active Mar 29, 2019
Basic example of inheritance in C++
View basic_inheritance.cpp
#include <iostream>
using namespace std;
class Device {
public:
int serial_number = 12345678;
void turn_on() {
cout << "Device is on" << endl;
}
View interface.cpp
#include <iostream>
using namespace std;
class Device {
public:
virtual void turn_on() = 0;
};
class Laptop: public Device {
public:
You can’t perform that action at this time.