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 reference?

A reference is a quantity that holds the address of an object but behaves syntactically like that object. A reference cannot exist without object and must be initialized.

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.

What is a singleton? Write a simple implementation of a singleton.

Singleton is a class that can have only one instance. For singleton example, see Singleton pattern in "Design Patterns" of E.Gamma, etc.

Write a simple referenced-counted smart pointer class.

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

When and why should you avoid a multiple inheritance. What are the good examples of MI usage?

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 books did you read recently?

While this question seems to be a silly one, it is easiest to be prepared to. I think it worth to mention Meyers, Gamma, Coplien, Stroustrup, Schildt etc.

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.

What is the namespace?

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++ !

What is the difference between struct and class?

There are few differences:
All members of struct are public.
Default inheritance for struct is public, where as for class the default inheritance is private.

Describe the role of envelope and letter classes.

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 :)

What is the difference between "overloading" and "overriding"?

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.

Why do you need a virtual 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.

What is polymorphism?

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.

What is the purpose of separating a class implementation from its interface


What is encapsulation?

An object-oriented programming term for the ability to contain and hide information about an object, such as internal data structures and code. Encapsulation isolates the internal complexity of an object's operation from the rest of the application.

What is "inline" function?

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.

What is inheritance?

An object-oriented programming term. The ability of a subclass to take on the characteristics of the class it's based on. If the characteristics of the parent class change, the subclass on which it is based inherits those characteristics.