C + + concept __c++

Source: Internet
Author: User
Tags assert message queue win32
1. What is the idea of object-oriented program design?
A: The data structure and the methods of operation of the data structure are encapsulated to form an object.


2. What is a class.
A: Classify objects that have commonalities to form a set, which is called a class.


3. What are the two characteristics of the object? What is the meaning of distinction.
A: The objects are characterized by static and dynamic features.
Static characteristic refers to some attributes (member variables) that can describe an object, and dynamic characteristic refers to the behavior of the object (member function).


4. The declaration of a class in a header file makes sense of the definition of the class in the corresponding implementation file.
A: This can improve the efficiency of compilation, because the separate words only need to compile one time to generate the corresponding. obj file, again apply the class place, this class will not be compiled again, thus greatly improve the compilation efficiency.


5. Defines the function body of a member function within a class, which can have that attribute.
A: This function is automatically an inline function, which is replaced in code at the compile stage where the function is called.


6. What the member function uses to distinguish the member data of different objects. Why it can be distinguished.
A: This pointer points to the object's first address.


7. What are the four default functions that the C + + compiler automatically generates for the class?
Answer: default constructor, copy constructor, destructor, assignment function.


8. In which cases the copy constructor is invoked.
For:
1. When an object of a class initializes another object of the class;
2. If the function's formal parameter is the object of the class, the call function is combined with the formal parameter and the actual parameter;
3. If the return value of the function is a class object, the function call completes when it returns.


9. What is the formal difference between a constructor and a normal function? (The function of the constructor, its declarative form to analyze)
A: A constructor is a special member function of a class, which is typically used to initialize an object member variable.
The constructor must have the same name as the class name, it does not have any type, and does not return any values.


10. When you must rewrite the copy constructor.
A: When the constructor involves dynamic storage allocation space, write the copy constructor yourself, and make a deep copy of the function.


11. What is the order of invocation of the constructor?
Answer: 1. Call the base class constructor first
2. Initializing data members in the Order of declaration
3. Finally, call your own constructor.


12. The list of initialization members must be used.
A: A member of a class is an initialization of a constant member;
A member of a class is an object member initialization, and the object has no parameterless constructor.
When a member of a class is a reference.


13. What is a constant object.
A: A regular object is an object that cannot be modified on any occasion by the value of its members.


14. The meaning of the existence of static function.
A: Static private members cannot be accessed outside the class, and can be accessed by static member functions of the class;
When a class's constructor is private, it is not instantiated like a normal class, only a static member function can invoke the constructor.


15. There are ways to access the Non-public members of a class outside the class.
Answer: Friends, inheritance, public member functions.


16. What is called abstract class.
A: You don't have to define an object and use it as an inherited class only as a basic type.


17. The meaning of operator overloading.
A: The operation of data of a user-defined data type is consistent with the operation of data of the data type defined within.


18. What are the 5 operators that are not allowed to overload?
For:
1. * (Member pointer access operation symbol)
2.:: Domain Operators
3. Sizeof length operation symbol
4.. : Conditional operation Symbol
5.. (Member accessors)


19. Operator overloading in three ways.
A: normal function, friend function, class member function.


20. The flow operator cannot be overloaded by a member function of a class. General how to solve.
A: Because the overload of a member function of a class must be the first of its operators, the overload of the convection operation requires that the first parameter be a stream object. So it is usually solved by friends.


21. The difference and relation between the assignment operator and the copy constructor.
Answer: The same point: All is a copy of an object to another.
Different points: The copy constructor involves the creation of a new object.


22. In which case you want to invoke the destructor of the class.
Answer: At the end of the object lifecycle.


23. How to achieve the sharing of data between objects.
A: A class of static member variables to achieve data sharing between objects. A static member variable occupies its own independent space and is not private to an object.


24. What are the characteristics of a friend relationship?
A: one-way, not transitive, not inherited.


25. The order in which the members of an object are initialized.
A: Its order is completely unaffected by their order in the initialization table, only the order in which the member objects are declared in the class.


26. What is the relationship between a class and an object?
A: A class is an abstraction of an object, which is an instance of a class.


27. What is the Access property for a member of a class?
Answer: Public,protected,private.


28. const char *P and char * const p; The difference
For:
If the const is on the left side of the asterisk, then the const is used to modify the variable that the pointer points to, that is, the pointer to a constant;
If the const is on the right side of the asterisk, the const is the cosmetic pointer itself, that is, the pointer itself is a constant.


29. is not a parent class to write a virtual function, if subclasses cover its function without virtual, can also achieve polymorphism?
For:
The virtual modifier is inherited by stealth.
Virtual can be added without adding, subclasses cover its function without virtual, can also achieve polymorphism.


30. What does the function overload mean? It is different from the concept of virtual functions.
A: function overload is a function with the same name to complete different functions, compile the system in the compile phase by the number of function parameters, parameter types, function return value to distinguish between the call which function, that is, the implementation of static polymorphism. But remember: You can't implement a function overload simply by using the function return value differently. The virtual function is to declare a function as virtual function in the base class by using the keyword virtual. The implication is that the function may be defined in a future derived class or extended on the basis of a base class, and that the system can only dynamically determine which function to call at run time. So the realization is dynamic polymorphism. It embodies a portrait concept, which is implemented between the base class and the derived class.


31. Constructors and destructors can be overloaded, why?
A: Constructors can be overloaded, and destructors cannot be overloaded. Because constructors can have multiple and can take arguments, destructors can have only one and cannot take parameters.


32. How to define and implement a member function of a class as a callback function.
For:
The so-called callback function, is in advance of the system to register the function, let the system know the existence of this function, later, when an event occurs, then call the function to respond to the event.
When defining a member function of a class, add callback to the function before it is defined as a callback function, and the implementation of the function does not differ from the normal member function.


33. How the virtual function is implemented.
A: Simply use a virtual function table.


34. Abstract classes do not produce instances, so there is no need for constructors. Wrong


35. You can derive a new template class from a template class, or you can derive a non-template class. Right


What code is executed before the main function executes.
Answer: The constructor for the global object executes before the main function.


37. When there is no life in a Class A member variable and member function, then the value of sizeof (a) is how much, if not 0, please explain why the compiler did not let it zero. (Autodesk)
Answer: Definitely not zero. To give a counter example, if it is 0, declare a class A[10] object array, and each object occupies zero space, then there is no way to distinguish a[0],a[1] ... Out.


The difference between delete and delete []:
A: Delete will call only one destructor, and delete[will call each member's destructor.


39. To invoke the destructor of the parent class when the subclass is destructor.
A: It will be invoked. The order of the destructor calls is the destructor of the base class after the destructor of the class, that is, when the destructor of the base class is invoked, the information of the derived class is destroyed.


40. Advantages and disadvantages of inheritance.
1. Class inheritance is statically defined at compile time and can be used directly,
2, class inheritance can easily change the implementation of the parent class.
Disadvantages:
1. Because inheritance is defined at compile time, the implementation that inherits from the parent class cannot be changed at run time
2. The parent class usually defines at least part of the behavior of the subclass, and any changes to the parent class can affect the behavior of the subclass
3. If the inherited implementation is not appropriate to solve the new problem, the parent class must be overridden or replaced by a more appropriate class. This dependency limits flexibility and ultimately limits reusability.


41. Explain the difference between stacks and stacks.
A: Stack area-the compiler automatically assigns releases, holds function parameter values, local variable values, and so on.
The heap (heap) is typically released by the programmer, and if the programmer is not freed, the program may end up being reclaimed by the OS.


42. When is the constructor and destructor of a class called, do I need to call it manually?
A: The constructor is invoked automatically when the class object is created, and the destructor is invoked automatically by the system at the end of the class object lifetime.


43. When to Precompile:
A: Always use large code bodies that don't change frequently.
A program consists of multiple modules, all of which use a standard set of include files and the same compilation options. In this case, you can precompile all the included files into a precompiled header.


44. Multi-state function.
Answer: The main two:
1. Hide implementation details, so that the code can be modular, extended code modules, to achieve code reuse;
2. Interface reuse: For a class to inherit and derive, the correct invocation is guaranteed when using an attribute of an instance of any class in the family


45. The difference between a virtual function and a normal member function. Whether inline functions and constructors can be virtual functions.
The difference: The virtual function has the virtual keyword, there are dummy pointer and dummy function table, virtual pointer is the interface of virtual function, and ordinary member function is not. Inline functions and constructors cannot be virtual functions.


46. The order in which constructors and destructors are called? Why is a destructor virtual?
Answer: The order in which constructors are called: base class Constructors-object member constructors-derived class constructors; destructors are called in the reverse order of constructors. The destructor is virtual to prevent the destructor from being incomplete, resulting in memory leakage.


What functions can be accessed by a member variable of type Private in C + +?
A: can only be accessed by member functions and friend functions in this class


48. Please say the difference between the Private,protect,public three types of access restrictions in the class
A: Private is a proprietary type that is accessible only to member functions in this class; protect are protected, this class and inheriting classes can be accessed, public is publicly available, and any class can be accessed.


49. How to initialize a member variable in a class.
A: You can implement a constructor's initialization list or a function body of a constructor function.


50. When you need to use the "constant reference".
A: If you want to use the reference to improve the efficiency of the program, but also to protect the data passed to the function is not changed in the function, you should use the constant reference.


51. What is the difference between a reference and a pointer.
Answer, 1 The reference must be initialized, the pointer does not have to.
2 The reference cannot be changed after initialization, and the pointer can change the object being referred to.
3 There is no reference to a null value, but a pointer to a null value exists.


52. Describe the basic characteristics of real time systems
Answer, in a specific time to complete a specific task, real-time and reliability.


54. Whether global variables and local variables are different in memory. If so, what is the difference.
The global variable is stored in the static data area and the local variable is on the stack.


55. The stack overflow is generally caused by any reason.
Answer, no recycling of garbage resources


56. What functions cannot be declared as virtual functions.
Answer Constructor (constructor)


The encoding of the IP address is divided into two parts.
Answer IP address consists of two parts, network number and host number.


58. The parameter types that cannot be switch () are:
The parameter of the switch cannot be solid.


59. How to reference a global variable that has already been defined.
Yes, you can use the reference header file in the way, you can also use the extern keyword, if you use a reference header file to refer to a global change that is declared in the header file, and if you write that error, the error occurs during compilation, and if you use an extern reference, suppose you make the same mistake, There will be no error during compilation and error during connection


60. For a frequently used short function, in C language application what implementation, in C + + application what implementation?
Answer, c with a macro definition, C + + with inline

C + + is not type-safe.
Answer: No. Two different types of pointers can be cast (with reinterpret cast)


62. When there is no life any member variables and member functions in a Class A, then what is the value of sizeof (a), please explain why the compiler did not make it zero.
Answer: for 1. To give a counter example, if it is 0, declare a class A[10] object array, and each object occupies zero space, then there is no way to distinguish a[0],a[1] ... Out.


63. Briefly describe the difference between arrays and pointers.
A: Arrays are either created in the static store (such as global arrays) or created on the stack. Pointers can point to any type of memory block at any time.
(1) Changes in the content of the difference
Char a[] = "Hello";
A[0] = ' X ';
Char *p = "World"; Note that P points to a constant string
P[0] = ' X '; The compiler cannot discover this error, run-time error
(2) operator sizeof can be used to calculate the capacity of the number of groups (bytes). sizeof (P), what p gets for the pointer is the number of bytes of a pointer variable, not the amount of memory that P refers to.


How to transfer values in C + + functions
Answer: There are three ways: value delivery, pointer passing, reference passing


65. How to allocate memory
A: There are three ways of distribution,
1, the static storage area, is already allocated when the program compiles, throughout the run period exists, such as global variables, constants.
2, the stack allocation, the function of local variables are allocated from this, but the allocated memory is easy to limit.
3, the heap allocation, also known as dynamic allocation, such as we use New,malloc to allocate memory, with Delete,free to release the memory.


What is the role of extern "C"?
A: Extern "C" is a connection-exchange-specified symbol provided by C + + to tell C + + that this code is a C function. This is because the C + + compiled library function name will become very long, inconsistent with C generation, resulting in C + + can not directly call the C function, plus extren "C", C + + can directly call the C function.
Extern "C" is used primarily by referencing and exporting regular DLL functions, and in C + + or C-header files when C + + is included. Use the front plus extern "C" keyword. The real purpose of this statement of extern "C" can be summed up in one sentence: To achieve mixed programming between C + + and other languages.




67. What function to open a new process, thread.
Answer:
Threads: Createthread/afxbeginthread, etc.
Process: CreateProcess, etc.


What's the difference between SendMessage and postmessage?
Answer: SendMessage is blocked, and so the message is processed, the code can go to the next line of SendMessage. PostMessage is non-blocking, and the code immediately goes to the next line of PostMessage, regardless of whether the message has been processed.


What is the main function of CMemoryState?
Answer: Check memory usage to resolve memory leak problem.


What is the difference between #include <filename.h> and #include "filename.h"?
A: For #include <filename.h>, the compiler starts searching from the standard library path filename.h
For #include "filename.h", the compiler starts searching from the user's work path filename.h


71. What is the purpose of the processor identification #error?
A: Output an error message at compile time and abort to continue compiling.


!defined #if (Afx_..._hade_h)
#define (Afx_..._hade_h)
......
#endif作用.
A: Prevent the header file from being repeatedly referenced.


73. What to pay attention to when defining a macro.
A: Each formal parameter and the entire expression in the definition section must be enclosed in parentheses to avoid unexpected error occurrences


74. The array changes the type when it does the function argument.
A: Arrays become pointer types when you make arguments.


75. The system will automatically open and close the 3 standard files are.
(1) standard input----keyboard---stdin
(2) Standard output----display---stdout
(3) standard error output----Display---stderr


76. The number of char, int, float and double in the Win32.
(1) Char occupies 8 bits
(2) Int occupies 32 bits
(3) Float occupies 32 bits
(4) Double occupancy 64 digits


The difference between strcpy () and memcpy ().
A: strcpy () and memcpy () can be used to copy strings, strcpy () copies end With ', ' but memcpy () must specify the length of the copy.


78. Explain how define and const differ in grammar and meaning.
A: (1) #define是C语法中定义符号变量的方法, symbolic constants are only used to express a value, in the compilation phase the symbol is replaced by the value, it has no type;
(2) const is a method of defining constant variables in C + + syntax, the constant variable has variable characteristics, it has a type, there is a memory cell named in it, and can measure length with sizeof.


79. Tell the difference between character constants and string constants, and use operator sizeof to calculate what's not.
A: The amount of constants is a single character, the string constant ends with ' and ', using operator sizeof to compute more than one byte of storage space.


80. Briefly describe the advantages and disadvantages of global variables.
A: Global variable is also called an external variable, it is defined outside the function variable, it belongs to a source program file, it saved the last modified value, easy data sharing, but inconvenient management, easy to cause unexpected errors.


81. Summarize the application and function of static.
A: (1) The function body of the static variable is the function body, different from the auto variable, the memory of the variable is only allocated once, so its value in the next call will still maintain the last value;
(2) The static global variable in the module can be accessed by functions in the module, but not by other functions outside the module.
(3) The static function within the module can only be invoked by other functions within the module, and the scope of use of the function is limited to the module in which it is declared;
(4) A static member variable in a class is owned by the entire class and has only one copy of all objects of the class;
(5) A static member function in a class is owned by the entire class, and this function does not receive the this pointer, and thus can only access the static member variable of the class.


82. Summarize the application and role of Const.
A: (1) to prevent a variable from being changed, you can use the Const keyword. When you define the const variable, you usually need to initialize it, because there is no chance to change it again;
(2) For pointers, you can specify that the pointer itself is a const, or you can specify that the data referred to by the pointer is a const, or that both are specified as const;
(3) In a function declaration, const can modify the formal parameter to indicate that it is an input parameter and cannot change its value within the function;
(4) For a member function of a class, if it is specified as a const type, it indicates that it is a constant function and cannot modify the member variables of the class;
(5) For a member function of a class, it is sometimes necessary to specify that its return value is a const type so that its return value is not a "left" value.


83. What is a pointer. Talk about your understanding of the pointer.
A: The pointer is a variable that stores the memory address specifically;
The type of the pointer variable depends on the type of data it points to, before the data type is referred to
The characteristic of a pointer variable is that it can access the memory that it points to.


84. What is a constant pointer and what is a pointer to a constant variable?
A: The meaning of a constant pointer is that the address that the pointer points to cannot be changed, but the content that the address points to can change, and using a constant pointer can guarantee that our pointer cannot point to another variable.
A pointer to a constant variable is the address of the variable itself that can be changed, and can point to other variables, but the content it refers to cannot be modified. Pointer definition to a long variable,

85. The difference between a function pointer and a pointer function.
Answer: The function pointer is a pointer to a function entry;
A pointer function is the return value of a function as a pointer type.


87. Briefly describe the difference between the debug and release versions.
A: The debug version is a debug version and release version is the final, non-debug version released to the user,


88. Several typical applications of pointers.
For:
int *p[n];-----An array of pointers, each of which is a pointer to an integer data.
Int (*) p[n];---p is a pointer to a one-dimensional array, and this one-dimensional array has n integer data.
int *p ();------function takes back the pointer, and the pointer points to the returned value.
Int (*) p ();----p is a pointer to a function.


What is the difference between a static function and a normal function?
A: The static function has only one copy in memory, and the normal function maintains a copy of each call


The difference between struct (structure) and Union (union).
Answer: 1. Structs and unions are made up of a number of different data type members, but at any one time the union holds only a selected member (all members share an address space), and all members of the structure exist (different host addresses for different members).
2. Assigning values to different members of the Union will be overridden for other members, the value of the original member is not present, and the assignment to different members of the struct is not mutually affected.


The difference between class and struct.
A: The members of the struct are publicly owned by default, and the members of the class are private by default.


92. Briefly describe the enumeration type.
A: Enumeration facilitates the definition of a set of constants once, which is convenient to use;


The role of A. assert ().
A: ASSERT () is a macro that is used frequently when the program is run, when it evaluates the expression in parentheses, and if the expression is False (0), the program reports an error and terminates execution. If the expression is not 0, the following statement continues to execute. This macro usually determines whether there is a clear illegal data in the program, if the termination of the program to avoid serious consequences, but also easy to find errors.


94. Whether local variables and global variables can have the same name.
Answer: Yes. The local screen will mask the global. To use global variables, you need to use the "::" (field operator).


95. The local variable of the program exists in (the stack), the global variable exists in (the static area), and the dynamic request data exists in (the heap).


96. When to use a constant reference.
A: If you want to use the reference to improve the efficiency of the program, but also to protect the data passed to the function is not changed in the function, you should use the constant reference.


97. The benefits of separate declarations and implementations of the class.
Answer: 1. Play a protective role;
2. Improve the efficiency of compiling.


What parts of the Windows Messaging system are composed of.
A: It's made up of 3 parts:
1. Message Queuing: The operating system is responsible for maintaining a message queue for the process, the program running continuously from the message queue to obtain messages, processing messages;
2. Message loop: The application keeps getting messages and processing messages through the message loop.
3. Message processing: The message loop is responsible for distributing messages to the relevant Windows using the associated window process functions for processing.


99. What is a message map.
A: Message mapping is about letting programmers specify MFC classes (classes that have message processing capabilities) to handle a message. The programmer then completes the processing function to implement the message processing function.


100. What is the difference between UDP and TCP?
A: TCP is all called Transmission Control protocol. This protocol can provide connection-oriented, reliable, point-to-point communication.
The UDP full name is the user message protocol, which can provide unreliable point-to-point communication without connection. With TCP or UDP, it depends on which aspect of your program. Reliable or fast.


What is the main implementation step for Winsock to establish a connection?
For:
Server-side: socket () establish socket, bind (BIND) and listen (listen), with accept () Waiting for client connection, accept () found a client connection, create a new socket, itself to start waiting for the connection. The newly generated socket uses send () and recv () to write the data until the data exchange is complete, closesocket () closes the socket.
Client: Socket () to establish sockets (), connection (connect) server, after the connection using Send () and recv (), on the socket read data, until the data exchange finished, closesocket () close socket.


102. The main means of communication between processes.
Answer: semaphores, pipelines, messages, shared memory


103. What are the three dynamic link libraries that make up the Win32 API functions?
A: Kernel library, user interface management library, graphics device interface library.


104. The steps to create a window are.
A: Populate a window class structure-> register this window class-> and then create a window-> display window-> Update window.


105. What is the difference between modal dialog boxes and modeless dialogs?
A: 1. The calling rule is different: the former is invoked with DoModal (), which is displayed by attributes and ShowWindow ().
2. The modal dialog box can be used without the user being able to perform other actions before it is closed, rather than a modal dialog box.
3. Non-modal dialog boxes must be created with their own common constructors, and the Create () function called.


106. Remove the data from the edit box to the associated variable, and what is the function that shows the associated variable's data on the edit box.
Answer: UpdateData (TRUE), UpdateData (FALSE).


107. Brief introduction to GDI.
A: GDI is the abbreviation of graphics Device Interface, translated as: Graphics device interface; A device-independent library of functions in a Windows application that produces graphics and text output on different output devices.


108. Windows messages fall into several categories. And to do a brief description of various types.
For:
1. Window message: A window-related message, except WM_COMMAND all the messages that start with wm_;
2. Command message; For processing user requests, messages expressed in WM_COMMAND;
3. Control notification message: Unified by Wm_notift said,
4. User-defined messages.


109. How to customize messages.
A: Using Wm_user and WM_APP two macros to customize messages,


110. Briefly describe the relationship between Visual C + +, Win32 API, and MFC.
A: (1) Visual c+ is an integrated, visual programming environment based on C + + programming language;
(2) The Win32 API is a set of application interfaces provided by the 32-bit Windows Operations System in C/s + + form;
(3) MFC is the encapsulation of the Win32 API, simplifying the development process.


111. How to eliminate the two semantics of multiple inheritance.
Answer: 1. Member Qualifier 2. Virtual base class


112 What is called static correlation, what is called Dynamic Association
A: In polymorphism, if a program can determine the actual execution action at compile time, it is called a static association,
If you wait until the program runs to determine if it is called Dynamic Association.


Two necessary conditions for 113 polymorphic
A: 1. A pointer or reference to a base class points to a derived class object 2. Virtual function


114. What is called a smart pointer.
A. When a pointer to another class object exists in a class, the pointer operator is overloaded, and the current class object can invoke the members of the other class as if it were a member of its own.


115. When you need to use a virtual destructor function.
A. When the base class pointer points to a derived class object that is generated with the new operator, when the delete base class pointer is not freed from the partial release of the derived class, a virtual destructor is required. Add: Virtual functions are virtual functions that let derived classes call the base class.


116. MFC, which class inherits most of the classes from?
Answer: CObject


117. What is a balanced binary tree.
A: The left and right subtrees are balanced binary trees, and the value of the depth difference between the left and the subtree is not greater than 1.


118. Statement for (; 1;) What's the problem? What does it mean.
A: infinite loops, same as while (1).


119. The process of deriving a new class goes through three steps
A: 1. Absorbing base class members 2. To transform the base class member 3. Add new Members


121. TCP/IP establishes the connection process
A: In the TCP/IP protocol, the TCP protocol provides a reliable connection service, using three handshake to establish a connection.
First handshake: When establishing the connection, the client sends the connection request to the server, and enters the Syn_send state, waits for the server to confirm;
Second handshake: The server receives the client connection request, sends to the client to allow the connection reply, at this time the server enters the SYN_RECV state;
Third handshake: The client receives the server to allow the connection reply, sends the confirmation to the server, the client and the server enters the communication state, completes three times handshake


122 memset, the difference between memcpy.
A: Memset is used to set all of the memory space to a certain character, typically used to initialize the defined string to ' ".
memcpy is used to make a memory copy, you can copy any data type object, you can specify the data length of the copy;


123. In C + + programs to invoke the compiler compiled by the C compiler function, why add extern "C".
A: the C + + language supports the function overload, and it does not support function overloading. The name of the function that is compiled by C + + in the Library
Different from the C language. Suppose that the prototype of a function is: void foo (int x, int y), the function is _foo in the library after the C compiler is compiled, and the C + + compiler produces names like _foo_int_int. C + + provides an extern "C" of the specified symbol, "C." To resolve the name matching problem.


124 How to define a pure virtual function. What is called a class that contains pure virtual functions.
A: After the virtual function is added = 0, the class containing the virtual function is called an abstract class.


125. The prototype of the known strcpy function is:
char * strcpy (char * strdest,const char * strsrc), does not call library functions, implements strcpy functions. Where Strsrc is the original string and strdest is the target string.
Answer:
Char *strcpy (char *strdest, const char *STRSRC)
{
if (strdest = null | | strsrc = NULL)
return NULL;
if (strdest = = strsrc)
return strdest;
char *tempptr = strdest; The pointer tempptr the address of the strdest;
while ((*strdest++ = *strsrc++)!= ' \\0 ')//NOTE: Don't forget the escape character;
;
return tempptr; Returns the address to which the pointer is addressed;
}


126. The prototype for the known class string is:
Class String
{
Public
String (const char *STR = NULL); Normal constructors
String (const string &other); Copy Constructors
~ String (void); destructor
String & operate = (const string &other); Assignment function
Private
Char *m_data; Used to save strings
};
Please write the above 4 functions of string.
Answer:
Normal constructors
string::string (const char *STR)
{
if (str = null)//strlen throws an exception when the argument is null this step is judged
{
m_data = new Char[1];
M_data[0] = ';
}
Else
{
m_data = new Char[strlen (str) + 1];
strcpy (M_DATA,STR);
}
}
Copy Constructors
string::string (const String &other)
{
m_data = new Char[strlen (other.m_data) + 1];
strcpy (M_data,other.m_data);
}
Assignment function (overloaded operator)
String & string::operator = (const string &other)
{
if (this = = &other)
return *this;
delete []m_data;
m_data = new Char[strlen (other.m_data) + 1];
strcpy (M_data,other.m_data);
return *this;
}
destructor
string::~ String (void)
{
delete []m_data;
}


127. The difference between overloading, overriding, and hiding a class member function
Answer:
Features that are overloaded by member functions:
(1) The same range (in the same class);
(2) The function name is the same;
(3) different parameters;
(4) virtual keyword is optional.
Overlay refers to a derived class function that overrides a base class function, characterized by:
(1) different ranges (in derived classes and base classes, respectively);
(2) The function name is the same;
(3) the same parameter;
(4) The base class function must have the virtual keyword.
"Hide" means that a function of a derived class masks a base class function with the same name as the following rule:
(1) If the function of the derived class has the same name as the function of the base class, but the parameters are different. At this point, the function of the base class is hidden, regardless of the virtual keyword (Note that you are not confused with overloading).
(2) If the function of the derived class has the same name as the function of the base class, and the parameters are the same, the base class function does not have the virtual keyword. At this point, the function of the base class is hidden (note that it is confused with overrides)
Related Article

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.