C++

Print

#include <iostream>
cout << "Hello World";

Variables

int *x; // pointer

int y = 4;
int& ref = y; // reference (must be initialized)

Data types

bool x;

// String
#include <string>
string x;

Functions

void swap(int &x, int &y) {
    int temp;
    temp = x;
    x = y;
    y = temp;
    return;
}

/* call by reference */
swap(a, b)

Classes

class MyClass {
    public:
        MyClass() { // Constructor
            // statement
        };
        double x;
        double myMemberFunction() {
            // statement
        };

    private:
        double y;

    // can be accessed in child classes
    protected:
        double z;
}

// Instantiation
MyClass myclass;

// Inheritance
class MyDerivedClass: public MyBaseClass {
    // ...
}

// Function overloading
class MyClass {
    public:
        void myFunction(int i) {
            // ...
        }
        void myFunction(double f) {
            // ...
        }
        void myFunction(char c) {
            // ...
        }
}

// Polymorphism
class MyBaseClass {
    public:
        virtual int myFunction() {
            // ...
        }
}

class MyDerivedClass1: public MyBaseClass {
    public:
        int myFunction() {
            // ...
        }
}

class MyDerivedClass2: public MyBaseClass {
    public:
        int myFunction() {
            // ...
        }
}

Interfaces

class MyAbstractClass {
    public:
        // Pure virtual function
        virtual int myFunction() = 0;
}