Skip to content

Instantly share code, notes, and snippets.

View kateolenya's full-sized avatar

Kateryna kateolenya

View GitHub Profile
@kateolenya
kateolenya / template_class.cpp
Last active April 26, 2019 12:25
Example of class template in C++
#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;
#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 / template_class_spec.cpp
Last active May 6, 2019 08:55
Example of specialized template class in C++
#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 / overloaded_op.cpp
Last active April 25, 2019 10:46
Example of overloaded operator in C++
#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;
@kateolenya
kateolenya / overload_op_custom.cpp
Last active April 25, 2019 10:52
Example of overloading built-in operator to add support for custom type in C++
#include <iostream>
using namespace std;
class One_value {
public:
int a;
void set_value (int arg) {
a = arg;
}
// Overload + operator