A: There is nothing like Virtual Constructor. The Constructor can’t be virtual as the constructor is a code which is responsible for creating an instance of a class and it can’t be delegated to any other object by virtual keyword means.
Shortly, friend class or function is a class or a function that declared friend of an other class. The idea behind friend class is to provide the access to the private and protected members or member functions of the friend class. There is a lot of controversial opinions on this topic and you should not usually use friends as it is a hole in your design. One of the examples where it's used is a momento design pattern.
In C++ I can declare a reference to a pointer. Can I not also declare a pointer to a reference? Why or How?
No, you cannot. It is explicitly stated in C++ spec that pointers to references are prohibited.
What is a pure virtual method (function)? What is the syntax for a pure virtual method? What is an abstract class?
Pure virtual function is a function that declared with "=0;" specifier. Pure virtual function does not have body and must be overridden in the derived class. The syntax for pure virtual function is virtual void foo() = 0; Abstract class is a class with at least one pure virtual function.
Singleton is a class that can have only one instance. For singleton example, see Singleton pattern in "Design Patterns" of E.Gamma, etc.
This question, in fact, is quite simple. I will not give you an example here, but look at auto_ptr (STL) and CComPtr (ATL) in order to provide your own implementation of reference-counted smart pointer class. Check also http://web.ftech.net/~honeyg/articles/smartp.htm
You should avoid so called diamond structure where a class derives from several base classes which, in turn, have common base class. Good example of MI is an ATL which is based on the idea of MI.
What is the virtual destructor. When and why do you need it? (Be surprised if you are not asked this question!)
Destructor implemented by declaring a base class's destructor with the keyword virtual. A virtual destructor ensures that, when delete is applied to a base class pointer or reference, it calls the destructor implemented in the derived class, if an implementation exists.
A namespace allows you to resolve conflict of the global identifiers when you use, for example, two different libraries of different vendors, which use the same names. Of course, if the vendors of libraries also use the same name for the namespace, you cannot resolve the name conflict with namespace feature of C++ !
I was actually asked this question at one of my interviews. I guess the single purpose of this question is to paralyze the interviewee. In my case the interviewer has achieved the goal and I am glad I did not pass an interview to that company. The interviewer actually tried to fetch a basic overview of C++ paradigms and design patterns (this envelope/letter paradigm is described in the book of Coplien from 1995) While I do not question the importance of design patterns, all I was talking to agreed that in this form the question demonstrate inability of the interviewer to conduct the interview. You may safely ignore this question if you asked :)
Overloading is the practice of supplying more than one definition for a given function name in the same scope. The compiler is left to pick the appropriate version of the function or operator based on the arguments with which it is called. Overriding refers to the virtual functions, i.e. functions that ensure that the correct function is called for an object, regardless of the expression used to make the function call. For example, if the same function with virtual attribute is declared in base and derived class, the function from the derived class is invoked for objects of the derived class, even if it is called using a pointer or reference to the base class.
Virtual base classes offer a way to save space and avoid ambiguities in class hierarchies that use multiple inheritance. Each nonvirtual object contains a copy of the data members defined in the base class. When a base class is specified as a virtual base, it can act as an indirect base more than once without duplication of its data members. A single copy of its data members is shared by all the base classes that use it as a virtual base.
Labels: Virtual base class
An object-oriented programming term. The ability to have methods with the same name, but different content, for related classes. The procedure to use is determined at run time by the class of the object. For example, related objects might both have Draw methods. A procedure, passed such an object as a parameter, can call the Draw method without needing to know what type of object the parameter is.
inline keyword before name of the function allows the compiler to insert a copy of the function body into each place the function is called. Therefore, the size of the code is increasing, but speed of execution is also increasing. You should mention that there are circumstances (e.g. recursive functions) when compiler is allowed to ignore inline keyword.