C ++ problem set

Source: Internet
Author: User


1: What is the difference between C and C ++:
C ++ supports object-oriented programming and is compatible with C-language process-oriented programming.

2: What is the difference between VB and C ++:
VB is an object-based language with the concepts of objects and classes, but it is not good for inheritance and polymorphism implementation.

3: What is the difference between VC and C ++:
VC can be viewed as a combination of C ++ and MFC base class libraries.

4: What should I pay attention to when declaring a reference? What should I pay attention to when returning a reference to a function:
1. You must declare the referenced object when defining the reference.
2. The referenced object cannot be changed.
3. Numbers, constants, and expressions cannot be referenced.
If the function is referenced, a local variable cannot be referenced.

5. What is the difference between reference and pointer:
Pointer: you can point to different addresses at will)
Reference: other variables cannot be referenced after declaration (from the beginning to the end)

6: differences between constant reference and constant pointer:
The constant reference value cannot be changed.
Can change the value of a constant pointer, but cannot change the point of a constant pointer.

7. Differences between default parameters and function overloading and applications:
The default parameter can be considered as a special case of function overloading. The default parameter is removed in Java.
Application: the default parameters can cover both common and special applications. However, function Overloading is required for more flexible processing.

8: void add (int A, int B) and INT add (int A, int B, int C = 0) are correct function overloading:
No, there may be ambiguity

9: void add (int A, int B) and INT add (const Int & A, const Int & B) are correct function overloading:
No. The reference of an integer is also an integer.

10: what is the use of inline functions? Is it possible to add the inline keyword before the function name to become an inline function? :
Purpose: saves the overhead of calling functions and speeds up operation.
Not necessarily, the compiler will automatically optimize

11: when to use: Operator:
Out-of-class implementation methods, reference static members of a class, etc.

12: differences between static and common members:
1. Static members can be directly referenced without instantiation.
2. Static attributes can have initial values.
3. Only static members can be accessed in static methods.
4 static members generally describe the common features of objects"

13: An Example of static application:
A chain store is a class, and the store name attribute should be static (class alias)

14: Role of constructor and destructor:
The constructor is used to initialize attributes and allocate memory space for the pointer. The Destructor is used to release the allocated space.

15: differences between the new/delete operator and malloc/free:
1 New/delete is a C ++ standard function with High Efficiency
2 new automatically obtains the allocated size for ease of use
3 New/delete triggers constructor/destructor

16: Write an example of allocating 100 space for the int pointer and then recycling it:
Int * P = new int [100];
Delete [] P;

17: What is light replication and deep replication:
When the class contains the pointer attribute, the shortest copy only copies the address, and the deep COPY Copies the content.

18: Write a class to simulate CIN and cout:
Class mycout {
Public:
Mycout & operator <(int ){
Printf ("" % d "", );
Return * this;
}
}

19: Exception Handling for C ++:
Is try, catch model"

20: What are the advantages of C ++ compared with VB exception handling:
C ++ Exception Handling distinguishes between normal code and Exception Handling Code, and is more complete in throwing user-defined exceptions.

21: Briefly describe four inheritance models in C ++:
Single inheritance, multiple inheritance, hierarchical inheritance, multi-pole inheritance

22: in the figure, if the Class A and C have the same name ABC, how can we reference it:
Instantiate the object d of D. You can use D. a: ABC () or D. b: ABC () references the method in A, D. c: ABC () references the method in C

23: will the subclass inherit all contents of the parent class? :
Private Members are not inherited.

24: In the figure in question 22, what is the sequence of constructor and destructor after the object of D is instantiated? :
A () --> B () --> C () --> D () --> ~ D () --> ~ C () --> ~ B () --> ~ A ()

25: If a constructor with parameters exists in the parent class, the constructor without parameters should also be provided. Why? :
This is because the child class recycles constructors that call parameters not included in the parent class before instantiation (unless the child class declares to call the constructors with parameters in the parent class, editing

The interpreter will not generate Default constructors for the parent class, and an error will occur.

26: What is override? What is the difference between overload and overload? :
Override: function override, which occurs in the parent class and subclass. The declaration of the source function of the subclass override function and the parent class must be completely consistent.
Overload: function overload. A set of overloaded functions must have different parameters.

27: Can Parent and Child class objects be converted to each other? :
Is one-way. You can assign a subclass object to a parent class object, or point the parent class pointer to a subclass, but not vice versa.

28: What Can inheritance do? :
Code reuse
Three phases of code reuse:
1 replication disadvantage: scattered code
2 modular disadvantages: difficult to maintain and expand
3 inherit"

29: Can a parent class pointer call a method in a subclass after pointing to a subclass object? :
No, unless the methods in the parent class are declared as virtual
Note: you cannot use the parent class pointer to call special methods in the subclass.

30: Differences and applications between virtual and pure virtual functions:
Difference: pure virtual functions are generally not implemented
Application: it is necessary to implement this method in the parent class. Considering polymorphism, virtual functions can be used. If the parent class does not need to implement this method, but it is expected to be implemented in the subclass, pure virtual functions can be used.

31: Differences and applications between classes and abstract classes:
Difference: abstract classes cannot instantiate objects. The subclass of an abstract class must overwrite pure virtual functions in the parent class.
Application: classes are generally used to describe objects that exist in reality. abstract classes are used to describe concepts that do not exist in reality. For example, the abstract class "shape" and Class "circle ""

32: must the subclass override (implement) pure virtual functions in the parent class? What about virtual functions? :
If the subclass does not overwrite the pure virtual function subclass in the parent class, the object cannot be instantiated or changed to an abstract class. The virtual function subclass does not overwrite the object.

33: What is the purpose of a virtual destructor? :
Virtual destructor ensure that the destructor in the subclass can be called.

34: Write A polymorphism: such as CPU Product

35: Write a class factory:

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.