More on Classes Flashcards
method chaining
where several member functions can be called on the same object in a single expression
this
inside ever (non-static) member function, the keyword this is a const pointer that holds the address of the current implicit object
*this
we can have function return this by reference in order to enable method chaining
where should class definitions be written?
in a header file with the same name as the class
where should trivial member functions (access functions, constructors with empty bodies etc.) be defined?
inside the class definition in the header
where should non trivial member functions be defined
in the source (.cpp) file with the same name as the class
nested type
a type that is defined inside a class type (also known as a member type)
member type
a type that is defined inside a class type (also known as a nested type)
Can member functions defined inside a class template definition use the template parameters of the class template?
yes
Can member functions defined outside a class template definition use the template parameteres of the class template?
no, they must resupply a template parameter declaration, and shold be defined (in the same file) just below the class template definition
static member variables
static duration members that are shared by all objects of the class.
Static members exist even if no objects of the class have been instantiated.
Prefer to access them using the class name, the scope resolution operator and the members name
How do you initialise a static member inside the class definition?
Make the static members inline
static member functions
member functions that can be called with no object. They do not have a *this pointer, and cannot access non static data members
friend declaration
can be used to tell the compiler that some other class or function is a friend
friend
a class or function (member or non-member) that has been granted full access to the private and protected members of another class