Featured
Delegating Constructor
Reduce constructor boilerplate by delegating to another constructor in the same class.
class Foo { Foo(int x) : Foo(x, 'y') {} Foo(int x, char y) : x(x), y(y) {} };Member Initialiser List
Initialise class member variables before the constructor body runs.
class Foo { Foo(int arg) : val(arg) {} int val; };Structured Binding
Unpack pairs, tuples, and aggregates cleanly.
auto [x, y] = std::pair{1, 2};
Recently Updated
See moreMultiple Inheritance
Subclass extending from multiple base classes.
class Base1 {}; class Base2 {}; class Derived : public Base1, public Base2 {};Abstract Class
Class that cannot be instantiated but can be used as a base class for inheritance.
class Base { virtual void f() = 0; };Access Specifier
Set class member accessibility.
class Example { public: protected: private: };Boolalpha
Print booleans as "true"/"false" strings instead of the default 1/0.
std::cout << std::boolalpha << true << "\n" << false << "\n";Character Input
Write to standard input using I/O streams.
#include <iostream> std::cin >> var;Character Output
Print to standard output using I/O streams.
#include <iostream> std::cout << var << "\n";Delegating Constructor
Reduce constructor boilerplate by delegating to another constructor in the same class.
class Foo { Foo(int x) : Foo(x, 'y') {} Foo(int x, char y) : x(x), y(y) {} };Enumeration
User-defined data type to give integer constants meaningful names.
enum class Status { Stopped, Running, Paused };
For Beginners
See moreAccess Specifier
Set class member accessibility.
class Example { public: protected: private: };Boolalpha
Print booleans as "true"/"false" strings instead of the default 1/0.
std::cout << std::boolalpha << true << "\n" << false << "\n";Character Input
Write to standard input using I/O streams.
#include <iostream> std::cin >> var;Character Output
Print to standard output using I/O streams.
#include <iostream> std::cout << var << "\n";Delegating Constructor
Reduce constructor boilerplate by delegating to another constructor in the same class.
class Foo { Foo(int x) : Foo(x, 'y') {} Foo(int x, char y) : x(x), y(y) {} };Member Initialiser List
Initialise class member variables before the constructor body runs.
class Foo { Foo(int arg) : val(arg) {} int val; };Range-Based For Loop
Loop over containers without writing indices or iterators.
for (auto& element : container) { // Do something with element. }Structured Binding
Unpack pairs, tuples, and aggregates cleanly.
auto [x, y] = std::pair{1, 2};