Through search the netease and tencent IEG game two client development offers (UE4/c + +), on the eve of the interview, the author of the c + + has carried on the comprehensive review and summary, optimistic based problem can cover about 80% of the interview, just share with you the following of this paper comprehensive interview questions c + +/game development summary,
This series of articles is expected to have a "c + + base", "memory, STL, virtual function related", "data structure and algorithm", "operating system and network" four (follow-up may be adjusted), each is in the form of questions and answers all share and give the resources links, most of the answer is simple, need you to read carefully the specific content of the resources,
People think if you understand all these problems, most of the interviewer take you on c + + doesn't or won't further way to embarrass you, but want to thoroughly understand all the content is not easy, it involves the operating system, data structure, the principle of the computer systems, assembly and other basic content, involves books including "c + + Primer", "Inside the c + + Object Model" "Effctive c + +", "More Effctive c + +" "c + + Template", "the Design and Evolution of c + +" "STL source analysis", "" deep understanding of computer systems, etc., want to want to do game development work related to help friends ~
Q: understand the const? Use the const what time? And what is the difference between macro definition?
Simple understanding, const purpose is to define a "will not be modified constant", you can modify variables, references, Pointers, can be used to function parameters, a member function to modify, member variables, using the const can reduce the probability of error code, we usually pay attention to distinguish between a constant pointer (pointer to a constant), and a pointer to constant (address is constant, the pointer to address remains the same), and reasonable use in function parameters, the specific situation you can refer to the following books and materials,
Reference books and materials: "Effctive c + +"
Q: what is the difference between the reference and pointer? What use a pointer?
1. The pointer can be null, and can't reference points to a null value,
2. The pointer can not initialize, reference must be initialized, this means that the quote don't need to test the validity
3. The target of a pointer can change at any time, and the reference initialization can be not refer to any other object again after
According to the above situation we know roughly know what time you need to use a pointer, but there's a kind of situation, when overloaded like [] symbols suggest return reference, this facilitate our writing habits is also easy to understand, because we are all such use at ordinary times, a [10]=10; Not * a [10]=10;
Reference books and materials: "More Effctive c + +"
Q: the pros and cons of the inline
Advantages: reduce the function call overhead
Disadvantages: increasing function volume, exe is too big, CPU resources, which can lead to the cache to hold (reduced cache hit), is not convenient to debug the debug is generally not inline, every change will increase to recompile the header files to compile time
Note: the inline is a request, the compiler has the right to refuse, there are 7 kinds of cases will be refused, virtual invocation, the volume is too big, there are recursive, variable number of arguments, through a function pointer call, the caller exception types, different declspec macros, etc.
Is mandatory inline forceinline literal meaning, general may be just the code do not limit the size, but for the above the situation still not inline, if there is no inline he returns a warning, the constructor destructor inline is not recommended, there may be additions after compiler optimizations, such as the initialization list,
Q: the effect of final and override, and using occasion
Final: it is forbidden to inherit the class or override the virtual function
Override: must cover the base class virtual function to match
Occasions (final) : I don't hope this class be inherited, such as vector, coders may not be good enough to understand the realization of the vector, or writers do not want other people to override a virtual function, as the name suggests, the final is ultimately
?Occasions (override) : the first, in the use of others' function library, or inherited while others wrote the class want to write a new function, may happen to like the original base class name of the function, the compiler for rewriting the base class function, the second is to write a function of a base class, but accidentally misspelled parameter mismatch or name, as a result, wrote a new virtual function
Reference books and information:
"c + + Primer"
Q: what is The ofthree rule? Why do you do?
If you need to explicitly declare either the destructor, copy constructor or copy the assignment operator yourself, you probably need toexplicitly declare all three of them. (the destructor, copy constructor, assignment operator statement together as much as possible, If you define only one, the compiler will help you define the other two, and the compiler defined version may not be what you want)
Q: what you're not used to c + + 03/98 or don't like to use? What you used to the new features of c + + 11?
This question the most simple way is to see what the next version of the c + + features, new features must be meaningful,
Such as:
Auto, there are some iterator or map nested types, traversed more troublesome, auto it is convenient to write,
Initialization vector as well as a list of other containers, original want to like array initialization, need one by one, very troublesome,
Initial value problem in class, always need to put inside the constructor initializes, initialization list, it is a good but too much not initialized data,
Nullptr, c + + 11 before the NULL is generally defined so # define NULL 0, this can cause some function parameters matching problem, and nullptr can avoid this problem,
Thread, do not need to use other libraries to write multithreaded,
Smart Pointers shareptr, to some extent, solve the problem of memory leaks,
Rvalue references, reduce copy overhead,
Lambda function, simplify the structure of the simple function code,
, of course, if you can say some not correct or would be better to be considered, such as the difficulty of memory management (GC), no reflection and some c #, there is the c + + Java features, etc., said it would be great to deeper
Reference books and information:
"c + + Primer"
Q: Delete the array part of what will happen? Why is abnormal?
Under the VC is abnormal, actually delete the entire array of memory is not only include CRTHeader data size, the information such as the length of the array, if delete part will start from the position of the number of incoming, is problematic, VC under the array of memory layout refer to the following formula,
Formula 1) _CrtMemBlockHeader + & lt; Your Data> + gap [nNoMansLandSize]; This kind of data with the delete and delete [] are all the same!
Formula (2) _CrtMemBlockHeader + number + array elements & lt; Your Data> + gap [nNoMansLandSize];
If other compilers, maybe not an error, but only released a questionable array object, other objects neither released nor destructor,
Q: how do system know pointer bounds?
VC has a structure under _CrtMemBlockHeader, there is a Gap properties, this Gap arrays on your behind the pointer to the data, the default is 0 XFD, when detected after your data is not the time for zero XFD means your data across,
Q: what are the common c + + compiler optimization? Heard of RVO (NRVO)?
1. Constant replacement such as int a=2; Int b=a; Return b; May be optimized for int b=2; Return b; Further optimization to return 2;
2. The dead code elimination of return values and parameters such as the function and the expression is completely independent, direct can optimize away the code
3. The expression is expected to calculate and subexpressions constants of multiplication will be counted in the compile phase, the same expression can be merged into one variable to compute
4. Some return value to avoid copying consumption, can be optimized as a reference and on the function parameters, such as the RVO, NRVO,
RVO: function returns the value of the object if it is a new structural type is directly through a reference as a parameter to construct, to avoid creating a temporary "temp" object,
NRVO: further optimization of RVO, compared to the RVO, if a function creates a temporary variable before return, the temporary variables will be constructed, refer to the following code
Point3d Factory ()
{
Point3d Po (1, 2, 3);
The return Po;
}
//RVO optimized
Void Factory (Point3d & amp; _result)
{
Point3d Po (1, 2, 3);
_result. Point3d: : Point3d (Po);
return;
}
//NRVO optimized
Void Factory (Point3d & amp; _result)
{
_result. Point3d: : Point3d (1, 2, 3);
return;
}
NRVO directly over the structure of the temporary object,
(supplement: the optimization of the above different compilers may sometimes differ, want to find out Suggestions to check the assembly code, generally speaking function returns a temporary object of value type is the right value, through the register storage, so can't get the address)
Of course, there are a lot of optimization, here is differ a list, because these optimizations, you may not be able to set breakpoints in the debugging process, so need to close the optimization, and a little skill, static variables will not be optimized,
Reference books and information:
"Inside the c + + Object Model" (depth exploration of c + + Object Model)
Q: heard of mangling?
Mangling refers to the compiler to the function variables such as the description of a lot of information is added to the name used to convey more information, commonly used function overloading, compile time can put the return value type and function name are combined to distinguish the effect of the specific rules of the compiler,
Reference books and materials: "Inside the c + + Object Model" (depth exploration of c + + Object Model)
Q: member function pointer to understand? Can be converted into Void *? Why is that?
Can not be converted into a Void *, because a member function pointer size is not 4 bytes (32-bit machine), in addition to address also need this delta, index information, such as a member function pointer is more complex, advice given to read the following article,
Writing: a function pointer float (* my_func_ptr) (int, char *);
A member function pointer float (SomeClass: : * my_memfunc_ptr) (int, char *);
Q: describe the compilation process of C/C + + code?
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull