Page 140 - DCAP404 _Object Oriented Programming
P. 140
Unit 6: Constructors and Destructors
Friend Function: A function which is not a member of a class but which is given special permission Notes
to access private and protected members of the class.
Static Member Functions: Functions that can access only the static members.
Temporary Object: An anonymous short lived object.
6.10 Review Questions
1. Write a program to calculate prime number using constructor.
2. Is there any difference between List x; and List x();? Explain.
3. Can one constructor of a class call another constructor of the same class to initialize the
this object? Justify your answers with an example.
4. Should my constructors use “initialization lists” or “assignment”? Discuss.
5. What is the “Named Constructor Idiom”?
6. Does return-by-value mean extra copies and extra overhead?
7. What about returning a local variable by value? Does the local exist as a separate object, or
does it get optimized away?
8. Why cannot we pass an object by value to a copy constructor?
9. Why are classes with static data members getting linker errors?
10. Spot out the error in the following code and correct it.
class one
{
int x,y;
public:
one(int);
one(int);
one(int, int);
~one(int)
{
cout << “Object being destroyed!!”;
}
}
11. How is a copy constructor different from a constructor? Illustrate with suitable examples.
12. Debug the following code:
class interest
{
int principal, rate, year;
float amount;
public:
LOVELY PROFESSIONAL UNIVERSITY 133