These questions are designed to determine the skill level of a candidate in C++ and MFC. For testing purposes, I assign a maximum of two points to each question. If you are going to use this test, be aware that the answers I have are not always complete in that there may well be alternate answers to some of the questions. It is up to the test giver to know and understand the questions and their answers before administering the test. As time goes on, and I administer the test to more applicants, I will be adding to the answer section and modifying the questions. I inform the test taker that I am usually looking for the "short" answer. Some questions have two parts, which I mark as "QA and QB." --- C++ --- 1) QA. How is a virtual destructor declared (given class name is FooBar)? Ans.: virtual ~FooBar. What effect does declaring a destructor have in the following case: class A has a non virtual destructor class B has a virtual destructor. B inherits A. class C has a non virtual destructor. C inherits B. class C is instantiated in the following manner: C *c = new C[]; QB. Would the destructor for class B get called? No. QB. Would the destructor for class A get called? No. 2) What effect does the keyword "static" have on a function belonging to a class? Ans. (There are several qualities. A common answer to this question is that a static function is a global function. That is not really true.): The function does not have a "this" pointer; It may be invoked in the scope of a class; It can access the private (as well as public or protected) members of its class. 3) I have a class B and class A inherits class B so that class A : protected B { /* ... */ } Q. What is the effect of the keyword "protected" in this case. Ans.: from Stroustrup: "The access specifier for a blase class controls the access to members of the base class and the conversion of pointers and references. .. If B is a protected base, its public and protected members can be used only by member functions and friends of A and by member functions and friends of classes derived from A.: 4) Q. What is the chief difference between a class and a struct? Ans.: The members of a struct are public by default. The members of a class are private by default. Note: A common answer to this question is that a struct holds data, but not code. That is not true. 5) Q. If the following template declaration is legal, tell me what it does. If it is not, explain why. template Type min( Type A, Type B ) { return a < b ? a : b; } Ans. Yes, this is legal and it does exactly what it seems to do. It returns the least value between "a" and "b". This is a very simple template question and it is also used as a standard example when explaining templates. When the template is instantiated, it will be called with some type. That type could be an int, float, short, char, etc. ALTERNATE TO QUESTION 5. The above, is the simplest template question I could imagine. inline template Type min( Type A, Type B ); Q. Is the above declaration legal? If so, what does it do? If not, how could it be corrected? Ans. This one is more difficult. In fact, I think it is very difficult even though it seems simple. Here is why: a function template can be an inline function. Many programmers might instinctively avoid doing this. It is also the type of thing that you might expect some compilers to handle incorrectly. However, it *is* part of the standard. That said, the "inline" keyword is in the wrong place. The answer is: template inline Type min( Type A, Type B ); If you want to make it even *more* difficult, use this: inline template Type min( Type A, Type B ); The trick here, is the use of the "typename" keyword. This keyword can be substituted for "class," and is perfectly legal. The "inline" keyword, however, is still in the wrong place. Note: the above alternates to question five were ripped-off from Lippman and Josee Lajoie from their "C++ Primer: Third Edition." --- W I N D O W S --- 6) Q) In the MFC inheritance hierarchy, what is the topmost class? Ans.: CObject 7) Given: BEGIN_MESSAGE_MAP( theClass, baseClass ) Parameters theClass : Specifies the name of the class whose message map this is. baseClass : Specifies the name of the base class of theClass. // example for BEGIN_MESSAGE_MAP BEGIN_MESSAGE_MAP( CMyWindow, CFrameWnd ) //{{AFX_MSG_MAP( CMyWindow ) ON_COMMAND( IDM_ABOUT, OnAbout ) //}}AFX_MSG_MAP END_MESSAGE_MAP( ) Q) How would the above work? Ans.: The OnAbout function will be called when the IDM_ABOUT message is received. 8) Q) What MFC function is called to create a windows window? Ans. Create Description: virtual BOOL Create( LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); Creates a Windows child window and attaches it to the CWnd object. You construct a child window in two steps. First, call the constructor, which constructs the CWnd object. Then call Create, which creates the Windows child window and attaches it to CWnd. Create initializes the window’s class name and window name and registers values for its style, parent, and ID. 9) Q) Which of the following is inherited from CObject: CString, CTime, CSocket, CRect Ans.: CSocket is derived from CAsyncSocket is derived from CSyncObject, is derived from CObject. 10) If you are going to have printing facilities in your MFC program, what class will you be overriding (inheriting from)? Ans.: CView For extra credit, what member function will you probably override? Ans.: virtual BOOL OnPreparePrinting( CPrintInfo* pInfo ); Called by the framework before a document is printed or previewed. The default implementation does nothing. You must override this function to enable printing and print preview. Call the DoPreparePrinting member function, passing it the pInfo parameter, and then return its return value; DoPreparePrinting displays the Print dialog box and creates a printer device context.