Skip to content

Instantly share code, notes, and snippets.

Kateryna kateolenya

View GitHub Profile
@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 22, 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 22, 2019
Example usage of keyword 'virtual' in C++
View virtual_inheritance.cpp
#include <iostream>
using namespace std;
class Device {
public:
void turn_on() {
cout << "Device is on." << endl;
}
};
@kateolenya
kateolenya / diamond_problem.cpp
Last active Mar 22, 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 / constructor.cpp
Last active Mar 22, 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 / private_inheritance.cpp
Last active Mar 22, 2019
Example of private inheritance in C++
View private_inheritance.cpp
#include <iostream>
using namespace std;
class Device {
public:
int serial_number = 12345678;
void turn_on() {
cout << "Device is on" << endl;
}
@kateolenya
kateolenya / basic_inheritance.cpp
Last active Mar 22, 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;
}
@kateolenya
kateolenya / private_funct.h
Created Mar 14, 2019
Private function in C using static
View private_funct.h
#ifndef PRIVATE_FUNCT_H
#define PRIVATE_FUNCT_H
struct Contact;
struct Contact * create_contact();
static void print_numbers( struct Contact * some_contact );
void delete_contact( struct Contact * my_points );
#endif /* PRIVATE_FUNCT_H */
@kateolenya
kateolenya / private_funct.c
Created Mar 14, 2019
Private function in C using static
View private_funct.c
#include "private_funct.h"
#include <stdio.h>
#include <stdlib.h>
struct Contact
{
int mobile_number;
int home_number;
};
@kateolenya
kateolenya / main.c
Created Mar 14, 2019
Private function in C using static
View main.c
#include "private_funct.h"
int main()
{
struct Contact * Tony;
Tony = create_contact();
// print_numbers( Tony );
// will cause compile time error
delete_contact( Tony );
return 0;
You can’t perform that action at this time.