STL interview question 2

Source: Internet
Author: User

Http://wiki.xyzp.net/index.php? Title = Moto % E7 % AC % 94% E8 % af % 95% E9 % A2 % 98% E7 % 9B % AE-STL/C % 2B % 2B % E9 % 9d % A2 % E8 % af % 95% E5 % B8 % 88 & printable = Yes

2007 Motorola pen questions

1. Introduce STL and explain in detail how STL implements vector.

Answer:

STL (standard template library. It consists of container algorithm iterator.

STL has the following advantages:

You can easily search for data or Sort data among other algorithms. It is more secure and convenient to debug programs; even the codes written by people using STL on UNIX platforms can be easily understood (because STL is cross-platform ).

Vector is essentially a dynamic array, which dynamically increases the array space based on the increase of data.

2. If you use VC to develop programs, what are the common errors such as C2001, c2005, and c2011. Answer:

When learning VC ++, The lnk2001 error message is as follows:

Unresolved external symbol "symbol" (uncertain external "symbol ").

This error message is generated if the connection program cannot find the referenced function, variable, or tag in all the libraries and target files.

In general, there are two reasons for the error: first, the referenced function, the variable does not exist, the spelling is incorrect, or the usage is incorrect. Second, different versions of the Connection Library may be used.

Lnk2005 errors are often encountered in programming-repeated definition errors. In fact, lnk2005 errors are not very difficult to solve.

3. What are the differences between inheritance and Delegation? What should be considered when deciding to use inheritance or delegation.

In OOD and OOP, combination is better than inheritance.

Of course, the basis of polymorphism is inheritance, and there is no inheritance polymorphism.

When the object type does not affect the behavior of functions in the class, the template is used to generate such a group of classes.

When the object type affects the behavior of functions in the class, we need to use inheritance to obtain such a group of classes.

4. What are the differences between pointer and reference? If it is safer to pass a reference than to pass a pointer, why? Isn't it true if I use a constant pointer?

(1) The reference must be initialized at the same time as it is created, that is, it must be referenced to a valid object. The pointer does not need to be initialized during definition, and can be re-assigned anywhere after the definition.

(2) There is no null reference, the reference must be associated with a valid storage unit, and the pointer can be null.

(3) once the reference is initialized to point to an object, it cannot be changed to another object reference, and the pointer can be changed to point to another object at any time. assigning a value to a reference does not change the binding relationship between it and the original object.

(4) the creation and destruction of references will not call the copy constructor of the class.

(5) At the language level, the reference usage is the same as the object. At the binary level, the reference is generally implemented through pointers, but the compiler helps us complete the conversion.

There is no blank reference. Once the reference is initialized to point to an object, it cannot be changed to another object reference, which is very safe.

The const pointer still has a null pointer and may generate a wild pointer.

In general, reference is convenient and intuitive for both pointer efficiency and variable usage.

5. There are several ways to pass parameters. What method is used to implement multi-state parameter transfer, and what is the cause if no method is used;

Pass value, pass pointer or reference

6. Use a project to describe how to apply the design pattern.

Design Patterns are more concerned with expansion and reuse, and these two aspects are often ignored.

However, I do not recommend that you abuse the design pattern to make simple problems more complicated.

7. Introduce your understanding of the design model. (Many detailed questions are randomly asked in this process)

The concept of a design pattern is proposed by architectural designer Christopher Alexander: "Each pattern describes a recurring problem around us and the core of the solution to this problem. in this way, you can use the solution again and again without repetitive work. "The above definition is a broad definition of the design pattern. applying it to the field of object-oriented software forms a narrow definition of the design model.

We can simply think that the design pattern is a specific method to solve a specific Object-Oriented Software problem, and has risen to the theoretical level.

Differences between the framework and the design model:

1. The design pattern and framework have different problem domains. The design pattern targets object-oriented problem domains; and the framework targets specific business problem domains.

2. The design pattern is more abstract than the framework. The design pattern can generate code only when a specific problem is encountered. The framework can already be represented by code.

3. The design mode is an architecture element that is smaller than the framework. The framework can contain multiple design modes.

The design pattern is like the basic moves in martial arts. By reasonably combining these moves, a routine (framework) is formed. The framework is a semi-finished product.

8. What are the definitions of C ++ and C.

The structure of C language is only a combination of data.

The struct and class of C plus actually have almost the same functions, but the default access attributes are different.

9. Can the constructor be a virtual sweat volume? Why? Can destructor be purely virtual?

A constructor cannot be a virtual function. To construct an object, you must know exactly what to construct. Otherwise, you cannot construct an object.

The Destructor can be pure virtual functions.

10. Problems Related to the copy constructor, such as deep copy, shortest copy, and temporary objects.

Deep copy means that the resources and pointers are copied, while the light copy only copies the pointers and does not copy the resources.

In this way, the two pointers direct to the same resource, causing the same destructor twice, and the program crashes.

The overhead of a temporary object is smaller than that of a local object.

11. use UML to describe a project that you think can better reflect the idea of OOP. (It is recommended that this project be inherited, multi-state, and virtual functions are all reflected.) This question will probably be half of the interview time and will ask a lot of questions, you may be asked if you are not careful )....

12. The base class has a virtual function. Do the subclass need to be declared as virtual? Why.

Do not declare it irrelevant.

However, I always like explicit statements to make the code clearer.

13. C can also be reused by carefully Encapsulating some function functions. What are the advantages of C ++ classes.

This is not just the case.

OOD and OOP have fundamentally changed the program design patterns and ideas, which are of great significance and far-reaching significance.

Three basic features of a class: encapsulation, inheritance, and polymorphism.

14. What are the characteristics of C ++ and how to implement polymorphism? Draw the relationships between base classes and child classes in the memory.

The basis of polymorphism is inheritance, which requires the support of virtual functions. Simple polymorphism is very simple.

Subclasses inherit most of the resources of the parent class and cannot inherit constructor, destructor, copy constructor, operator = function, youyuan function, etc.

15. Why should abstract base classes and pure virtual functions be introduced?

The main purpose is to implement an interface.

16. Introduce the template and container. How to implement it? (You may be expected to implement it on the spot)

Templates are old, but the current generic programming is actually template programming. It embodies a general and general idea.

STL has seven major containers: vector, list, deque, MAP, multimap, set, and Multiset.

17. How do you understand MVC. A simple example is provided to describe its application.

The MVC mode is a special case of the observer mode. A typical structure is the document view architecture in MFC.

18. How to eliminate the ambiguity of Multi-inheritance.

Use virtual inheritance.

From http://wiki.xyzp.net/Moto%E7%AC%94%E8%AF%95%E9%A2%98%E7%9B%AE-STL/C%2B%2B%E9%9D%A2%E8%AF%95%E5%B8%88.htm"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.