Hello Everyone, I recently gave an online C++ test. Below are few of the questions I need help with. Could anyone please explain to me the correct answers?
1) Can we call virtual function from non-virtual function?
2) Can we call pure virtual function from constructor?
3) Benefits of Templates over overriding
1 2
|
i) One copy of code in memory
ii) Fast
| |
4)
Obj1 = obj2
points to the same memory location?
5) Rough Code below
1 2 3
|
Class Object1; (no object created)
Class Object2 obj2; (one object created)
cout << dynamic_cast< Object1>(obj2) << endl; ....... prints what?
| |
6) How to find a
substring in a map key
(syntax?), the key stores a string.
7) Returning an array from function (syntax of function signature?)
8) Default copy constructor does what
1 2
|
i) Reference to the original object of the same class
ii) Does nothing by default
| |
9) Assign const pointer to a non-const pointer
1 2 3 4
|
i) Reinterpret
ii) Dynamic_cast
iii) Const_cast
iv) Static_cast
| |
10) If we do not write a constructor, the compiler generates one for us. Is there a default destructor too?
11) How to print vector elements in a separate function having only a print statement
1 2 3 4 5
|
Rough Code
For_each(syntax for iteratring, printFunc) – syntax?????
For() {} – syntax?????
int printFunc(int i)
{cout << i << endl;}
| |
12) What does
double ( ## )
between two variables and
single ( # )
before one variable in macros mean?
e-g ...
{#xyz ## #jkl}
13)
1 2 3 4
|
Rough Code
Pointer1 ptr1 = new Pointer;
Pointer2 ptr2;
ptr2 = ptr1; ..... how to assign? Syntax
| |