Skip to content

Instantly share code, notes, and snippets.

Avatar

Kateryna kateolenya

View GitHub Profile
@kateolenya
kateolenya / template_class_spec.cpp
Last active May 6, 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;
T b;
public:
Two_values (T first_arg, T second_arg) {
a = first_arg;
@kateolenya
kateolenya / template_class.cpp
Last active Apr 26, 2019
Example of class template in C++
View template_class.cpp
#include <iostream>
using namespace std;
template <class T>
class Two_values {
T a;
T b;
public:
Two_values (T first_arg, T second_arg) {
a = first_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 () {
int p = 1;
@kateolenya
kateolenya / overloaded_function.cpp
Last active Apr 26, 2019
Example of overloaded function in C++
View overloaded_function.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;
}
@kateolenya
kateolenya / overload_op_custom.cpp
Last active Apr 25, 2019
Example of overloading built-in operator to add support for custom type in C++
View overload_op_custom.cpp
#include <iostream>
using namespace std;
class One_value {
public:
int a;
void set_value (int arg) {
a = arg;
}
// Overload + operator
@kateolenya
kateolenya / overloaded_op.cpp
Last active Apr 25, 2019
Example of overloaded operator in C++
View overloaded_op.cpp
#include <iostream>
using namespace std;
int main () {
int a = 5;
int b = 10;
char c = 'c';
char d = 'd';
bool t = true;
bool f = false;
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
You can’t perform that action at this time.