C++

C++

Major Updates

C++ introduces bool.

Enumerations define a new type.

References are alternate names for variables.

It is efficient to pass large structs as references.

Operators can be overloaded.

 

 

Calling Functions

Overloaded functions have the same number but different argument types. Type conversion is used for a best match.

Default arguments come after non-default arguments.

The use of a function or variable from a different namespace must be qualified by the name of the namespace.

To get a function to accept any type, ie polymorphic behaviour, declare it virtual. Selecting the right function is a run time decision.

 

Classes

Classes have access control private, protected and public.

A class defined with struct has members with default access public, defined with class they're default acces is private.

A member function with the same name as the class is the destructor. One constructor can be named.

The keyword this returns a pointer to the current object.

An unreferenced temporary object exists only during execution of a full expression.

A friend function can access the private members of a class instance it befriends.

Classes can inherit features of another class using :

 

Exceptions

If an exception is thrown the stack is unwound until a function is found that catches the exception.

A class is often used to define an exception.

 

Templates

Templates allow code to be evauluated at compile time rather than run time, and allow types to be parameters in a program.

Eg; template<class T> class Stack {

Where class T can be any C++ type.
Compiler Construction