Introduction to C++ I Flashcards
What is C++?
Object-oriented language built on top of C.
What are some functionalities of C++?
- Operator overloading
- We have classes and objects
- Namespaces for organisation
- Pass-by-reference
- In C++ usage of objects implicitly triggers default or programmer defined functions for managing lifecycle.
What are the types/visibility of member variables we can have in a C++ class?
- private
- public
- protected
- friend
- static
Where are constructors of classes typically declared?
In the public scope (can be protected or private).
What does public declaration of a class allow?
- Initialisation
- Copying (duplication of resource)
- Moving (transferring ownership of resource)
What does a destructor deceleration specify?
Destructor declaration specifies how to clean up a class type.
When are destructors callled?
Destructors are automatically called when a class is deleted (e.g. out of scope or explicitly free the memory allocated for the class).
What are member functions?
Functions of the class that do stuff. Specify name, parameters, return type.
What are const functions?
Functions that do not change the state of the class.
Can member function be declared and defined in the header class?
Yes, we can provide implementation as well in the header file.
What is the default visibility for a class member?
Private
What visibility can C++ class members be?
- private
- public
- protected
Where are private members accessible from?
Inside the class or through member functions.
Where are public members accessible?
Outside the class (they form the class interface) and should either be accessors or mutators.
Do we use header guards in C++?
Yes, they are needed in the header files.
What is the encourage method of storing declaration and implementation?
Store the declaration in the header and the definition/implementation in an implementation file (.cpp).
What are initialisation lists?
Used to set a member variable to function parameter value.
What is the this pointer?
A pointer to the current instance of the class object, only visible withing a member function of a class instance. Only needed if you have to refer to class member.
What is stored in the dereferencing of *this?
*this is the value at the address of the class instance.
What is overloading?
Multiple functions with the same name, but different parameters and qualifiers (e.g. const)
What are structs in C++?
They are classes where visibility is default public.
How are structs in C++ different to C?
Structs in C++ have the option to add functions to them but you don’t have to.
What happens when a class instance is out of scope?
The destructor is automatically called.
If we use the new keyword what must we use later in the program?
delete, when we have finished using a variable.