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
Code:
i) One copy of code in memory
ii) Fast
4)
Code:
Obj1 = obj2 ........... points to the same memory location?
5) Rough Code below
Code:
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
Code:
i) Reference to the original object of the same class
ii) Does nothing by default
9) Assign const pointer to a non-const pointer
Code:
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
Rough Code
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 ...13) Rough Code
Code:
Pointer1 ptr1 = new Pointer;
Pointer2 ptr2;
ptr2 = ptr1; ..... how to assign? Syntax