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.