1. Only a field name or an expression may be used for the ____ property in a calculated control.
2. #include using namespace std; class Point { private: int x, y; publi Point() : x(0), y(0) { } Point& operator()(int dx, int dy); void show() {cout << "x = " << x << ", y = " << y; } }; Point& Point::operator()(int dx, int dy) { x = dx; y = dy; return *this; } int main() { Point pt; pt(3, 2); pt.show(); return 0; }
3. Predict the output? #include #include #include using namespace std; class Test { int x; publi void* operator new(size_t size); void operator delete(void*); Test(int i) { x = i; cout << "Constructor called \n"; } ~Test() { cout << "Destructor called \n"; } }; void* Test::operator new(size_t size) { void *storage = malloc(size); cout << "new called \n"; return storage; } void Test::operator delete(void *p ) { cout<<"delete called \n"; free(p); } int main() { Test *m = new Test(5); delete m; return 0; }
4. Which of the following operator functions cannot be global, i.e., must be a member function.
5. Which of the following operators are overloaded by default by the compiler? 1) Comparison Operator ( == ) 2) Assignment Operator ( = )
6. How does C++ compiler differs between overloaded postfix and prefix operators?
7. How can we restrict dynamic allocation of objects of a class using new?
8. A constructor is called whenever
9. Operator overloading may lead to copies
10. Overload function in C++
11. Exact virtual function is decided at run-time
12. Which of the following operators should be preferred to overload as a global function rather than a member method?
13. Operator overloading is very much like function overloading
14. Derived class must implement pure virtual functions
15. Which of the following operators cannot be overloaded
16. An object of abstract class cannot be created
17. Operator overloading works only on pass by value
18. Polymorphism results in more memory because of:
19. The fields in a class of a C++ program are by default
20. Output of following program? #include using namespace std; class Test2 { int y; }; class Test { int x; Test2 t2; publi operator Test2 () { return t2; } operator int () { return x; } }; void fun ( int x) { cout << "fun(int) called"; } void fun ( Test2 t ) { cout << "fun(Test 2) called"; } int main() { Test t; fun(t); return 0; }