Test Flashcards
- Constructor declaration, can it return a type?
a constructor is declared by declaring a function with the same name as the class it is in. Constructors can’t return anything, not even a void.
- What is the difference between copy constructor and an assignment operator?
A copy constructor is used to initialize a previously uninitialized object from some other object’s data.
An assignment operator is used to replace the data of a previously initialized object with some other object’s data.
- Order of calling constructors
Base class constructors and derived class destructors are called first. Because the Derived class inherits from the Base class, both the Base class and Derived class constructors will be called when a Derived class object is created. When the main function is finished running, the object x's destructor will get called first, and after that the Base class destructor will be called. Inside Base constructor Inside Derived constructor Inside Derived destructor Inside Base destructor"
The order is:
Member variables are initialized to default values for all classes in the hierarchy
Then starting with the most derived class:
Variable initializers are executed for the most-derived type Constructor chaining works out which base class constructor is going to be called The base class is initialized (recurse all of this :) The constructor bodies in the chain in this class are executed (note that there can be more than one if they're chained with Foo() : this(...) etc
- Static element on initialisation list
A static element is created during the first initializaton of class’s object, is common (has the same value) for every object of that class, modifyng the value of static element in class means that the modified value is in every object’s of that class.
- Which operators can’t be overloaded ?
These operators can't be overloaded: . sizeof .* ?: \::
- Map and multimap, what’s the difference ?
map - container from STL, in other language is hash/dictionary, it's got key value and mapped value), #include map email; email["key"]="value";
multipmap:
Key in multipmap is not unique, as it is in map
- What is a weak aggregation ?
One object uses another, but is otherwise independend of it (won’t be destroyed if the other one is)
- Selective inheritance
cannot weaken or strengthen access to members/methods.
- Definition of Template
Templates are a feature of the C++ programming language that allows functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one.
Templates are of great utility to programmers in C++, especially when combined with multiple inheritance and operator overloading. The C++ Standard Library provides many useful functions within a framework of connected templates. (from wiki).
int tab[2][3] = {{1,2},{4}} What does this array look like? The unspecified elements of the array are set to 0.
int tab[10]; tab[9]= 10.7 what is the value of the last element of the array - the answer is 10, unless this is a trick question about the array structure or smth
- static variable
Preserves variable value to survive after its scope ends.
- inheritance
Classes can be extended by creating new classes which retain characteristic of the base class.
- Difference between public and private inheritace
Public and protected members of a base class are accesible from a derived class
Objects of derived class with private and protected inheritance cannot acces any data member of a base class
Objects of derived class with public inheritance can access only public member of a base class
- Which of the functions was initiated?
It was declared as a virtual but as a child was private
- Can we prevent from abort function operations.
We can instal the signal handler that gets called in such situation.
We can also set function _set_abort_behavior for visual c++
- Inheritance of exceptions
Its a class which catch and store all possible exceptions