#include <iostream>
cout << "Hello World";
int *x; // pointer
int y = 4;
int& ref = y; // reference (must be initialized)
bool x;
// String
#include <string>
string x;
void swap(int &x, int &y) {
int temp;
temp = x;
x = y;
y = temp;
return;
}
/* call by reference */
swap(a, b)
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() {
// ...
}
}
class MyAbstractClass {
public:
// Pure virtual function
virtual int myFunction() = 0;
}