Home > Back-end >  Three interviews problem, turn to the great god answers
Three interviews problem, turn to the great god answers

Time:10-02

Topic 1
The class Object {
Public:
The Object () {init (); }
Virtual void init () {}
};
The class GameObject: public Object {
Public:
Virtual void init () {m_TypeName="GameObject"; }
STD: : string m_TypeName;
};
Int main ()
{
GameObject GameObject.
STD: : cout & lt; <"GameObject type, the name is" & lt; return 0;
}
Could you tell me the code run results? The reasons for this result? How to change to make the code in line with expectations?





Question 2
Float zero=0, three=3, four=4;
The class Complex
{
Public:
Float & amp; X, & amp; y;
Complex () : x (zero), y (zero) {}
Complex (float& Z) : x (y), y (z) {}
Complex (float& _x float& _y) : x (_x), y (_y) {}
};
Float square (const float& X)
{
return x * x;
}
Float absValue (Complex& C)
{
Return SQRT (square (c.x) + square (c.y));
}
Int main ()
{
Complex c (four);
Printf (" absolute value is % g \ n ", absValue (c));
return 0;
}
Could you tell me the code run results? The reasons for this result? How to fix?








3
A tree nodes are defined as follows:
The class Node
{
Public:
Const char * m_FriendlyName;
Node * m_ParentNode;
Node * m_LeftChildNode;
Node * m_RightChildNode;
};
Void printNode (Node * p_Node)
{
If (p_Node!=0)
STD: : cout & lt; <"Node:" & lt; }
Please write code: 1, by calling the printNode function to print all nodes of a tree structure; 2, according to the hierarchical order to print all nodes of the tree structure

CodePudding user response:

Question 1: how to modify the can make the code in line with expectations? What is expected?
STD: : string m_TypeName; In the base class Object inside the

Question 2: are a number of reference

Question 3: do not write,
  • Related