A collection of test questions for C + + (I.)

Source: Internet
Author: User
Tags message queue

<title>A collection of test questions for C + + (I.)</title> A collection of test questions for C + + (I.)
What does it mean to declare in the header file of a class and then implement it in the definition file?
On the one
hand, the implementation of the class is compiled only once, improve the efficiency of compiling, on the other hand can realize the separation of class interface and implementation, facilitate maintenance
The function body that implements member functions within the declaration of a class
This member function automatically becomes an inline function, which is replaced with code wherever it is used in the compilation phase
What the member functions do to differentiate different objects
different objects are distinguished by the this pointer implied by the ordinary member function. The code is shared between different objects of a class, and only the data is different, and the this pointer points to the first address of these different data memory locations.
Use cases for copy constructors
A. When using an object to initialize another object of the same type B. When a function call uses a class object as a formal parameter c. When the function return value returns a class object
When do I have to rewrite the copy constructor
when a member of a class needs to make a deep copy of the pointer, it needs to make dynamic memory allocations within the constructor used, and the corresponding dynamic memory release
within the destructor
Order of constructor calls
A. Calling the constructor of the base class B. Initializing data members of a class in the order in which they are declared c. Calling the class's own constructors
What happens when you have to use the Initialize member list
A. Members of a class have attributes that cannot be modified once initialized the normal property and the reference B. The member of the class is another class, and the class does not have a default constructor (that is, arguments need to be passed)
The meaning of the static member function of the class
compared to ordinary member functions, it is not necessary to generate objects, the cost of the this pointer, and a little more efficient, providing an appropriate implementation for functions that do not need to be instantiated.
What is the way outside the class to access non-common members of a class
friends, inheritance, and public member functions
Abstract class
cannot be used to create an object that can only be used as a base class for inheritance, except that at least one member function is a pure virtual function (declaration = 0, regardless of whether the function has implementation code)
The meaning of operator overloading
Provides a
consistent data manipulation interface for a custom data type with a language built
-in type
5 operators that do not allow overloading
. *,::, sizeof,?:,.
Why can't a stream operator be overloaded with member functions? General how to solve
overloading an operator within a class requires that the first operand of the operator be an object of this class, because the stream object belongs to the class of the standard library and cannot be overloaded with the flow operations of various custom classes in the standard library. Overloading of class flow operators is generally implemented by using the friend function of a custom class
What is the difference between an assignment operator and a copy constructor?
They all build another object of the class from one object of the class, but the copy constructor involves the construction of the object, and the assignment operator does not need to establish the object
When to invoke the function of the destructor of the class
At
the end of the object's life cycle, it is usually near the right curly brace closest to the object
How to share data between objects of a class
implemented by static member variables of a class, static member variables have their own independent storage space, and the data is shared by all members of the entire class and can be accessed.
The order in which the data members of the class are initialized
The order in which
they are initialized is determined by their order in the declaration of the class.
If the virtual function implements polymorphism, is it necessary for the keyword to be overridden in subclasses?
The
virtual keyword is inherited by stealth, even if the subclass does not add this keyword to achieve polymorphism
What is the difference between a function overload and a virtual function in implementing a function's polymorphism?
function overloading is a static polymorphism that is implemented during compilation by different function signatures (number of functions, number of function arguments, type of function arguments), and virtual functions are overridden in subclasses by inheritance relationships between classes and functions
.
Characteristics of a friend relationship
one-way, non-transitive, cannot inherit.
Can constructors and destructors be overloaded?
constructors can have more than one parameter and can be overloaded; destructors can only have one so it cannot be overloaded, and he has no arguments.
Implementation of virtual function
virtual function table (virtual table pointer)???
What code will be executed before the main function executes
The
constructor of the global domain object is executed before the main function executes
When no variables and functions are declared in a class, what is the sizeof class and why?
The
size is 1 to distinguish different objects of a class by assigning different memory addresses to different objects in the program.
The difference between delete and delete[]
Delete Calls only one destructor, which invokes the destructor for each object.
base class and derived class destructors and call order of constructors
During
object creation, the constructor of the base class is called first, then the constructor for the class, and the destructor is called in reverse. In the process of working with the constructor of the base class, the object of this class is not completely established, the information of this class is incomplete, and in the same way, in the process of destruction, the information of this class is destroyed in the process of the destructor work of the base class.
Advantages and disadvantages of inheritance
is a way of code reuse that provides some degree of flexibility, and the benefits are also limited.
When is the constructor and destructor of a class called, and by whom?
are automatically called by the system at the beginning and end of the life cycle of the class, respectively. Sometimes it can be called manually by the programmer.
Pre-compilation
multiple modules, not often changed.
Implementation of polymorphism in C + +
A. Static polymorphism, determined during compilation (function templates and function overloads, note Function default parameters), B. Dynamic polymorphism, determined during runtime (virtual function, overwrite, pointer, or reference)
The role of four characteristics in C + +
encapsulation enables code to be modular, inheritance makes code easy to extend, and polymorphism is for interface consistency and reuse, abstraction??? Concepts of (data abstraction, algorithm abstraction) classes, the concept of templates
Why cannot a normal function, static function, friend function be a virtual function
The
normal function will determine the code at compile time, cannot implement dynamic polymorphism, the static member function of the class has only one copy in the base class and all subclasses, the friend function does not have the inheritance characteristic, also cannot implement the dynamic polymorphism, therefore does not need to support the virtual function
Why an inline function cannot be a virtual function
inline functions are designed to expand code during compilation, and virtual functions are conceptually incompatible in order to support the execution of several different branches of code at run time.
Why a constructor cannot be a virtual function
A. Virtual function implementation requires virtual table support, when the virtual table has not been established B. A constructor cannot be called by a pointer or reference, so it does not have to be set to a virtual function C. The implementation of virtual functions requires a pointer or reference to determine the type of the object, the constructor is called when there is no complete object, cannot determine the object type, so cannot be set to a virtual function.
Why is the destructor of a base class best set to a virtual function?
because dynamic polymorphism supports the use of derived class objects through a base-class pointer or reference, when a derived class object needs to be refactored, only the destructor is a virtual function in order to properly refactor
What functions a private member of a class can be accessed by
can be accessed by member functions and friends of this class
Protected members of a class can be accessed by those functions
can be accessed by the class's member functions and classes derived from the friend and public and protected derivation methods
Frequently cited
both improve the efficiency of the program and protect the data passed to the function is no longer changed in the function
The difference between a pointer and a reference
The reference must be initialized, it cannot be changed after initialization, and pointers do not need to be, pointers can point to null values, references are not allowed.
The expression after switch cannot be a type
can be integer, character, Boolean, enum type, and cannot be considered floating-point data.
How to refer to a defined global variable
A. Global variables within the header file, you can refer to the header file directly after using B. If you define global variables in other source files, you can use the extern keyword with this global variable.
How short functions that are frequently used are handled in the C + + language
Use the
macro definition in the C language to use inline functions in the C + + language.
Three ways to allocate memory
static store allocations are determined during compilation, allocated on the stack, and dynamically allocated on the heap.
What's the use of extern "C"?
used to declare a specific program statement or block of statements in a C + + program as compiled by the C-language function naming convention.
What is the difference between defining constants using # define and const
#define是C语言预处理器的语法关键字, only constant substitution is performed during compilation; Const is the C + + language's method of defining a constant variable, it has a type, has memory allocations, and can be used to test the length with sizeof.
The difference between struct and class
The
default inbound property for struct members is public, while class's default inbound property is private.
Can local variables and global variables have the same name?
Yes, the local variable will mask the global variable; you need to access the global variable using:: Domain operator.
ASSERT macro
used to debug programs to avoid significant errors or illegal data in the program, which can be used #define NDEBUG to prohibit assert assertions in a specific version of a program
What parts of Windows Message Queuing are made up of
A. System Message Queuing, which is the responsibility of the operating system to deliver messages to a particular application's message Queue B. Application message loops, each application has its own message queue, and in the application message loop, continuously extracts messages from its own message queue and processes specific messages. The message is then referred to the Windows operating system to invoke the appropriate window handler. The window handler function, in addition to the messages that have been processed in the message loop, will be called by the operating system to handle the different messages.
What's the difference between SendMessage and postmessage?
SendMessage is the process of skipping Message Queuing and message loops directly to a particular window handler and waiting for the end of the message processing to be returned. PostMessage is to put the message in the application message queue, but does not wait for the message to end but returns immediately.
Message map
in MFC classes, programmers implement various processing of MFC class-to-operating system messages by mapping system messages to member functions of classes.
What are the three dynamic link libraries that make up the Win32 API?
Kernel32.dll, User32.dll and Gdi32.dll
Windows messages are categorized into categories and are briefly described for each class?
A. Window messages: Messages related to Windows, except for WM_COMMAND B. Command messages: Messages for processing user requests to WM_COMMAND represent C. Control notification message: Unified by WM_NOTIFY processing
What does it mean to declare in the header file of a class and then implement it in the definition file?
On the one
hand, the implementation of the class is compiled only once, improve the efficiency of compiling, on the other hand can realize the separation of class interface and implementation, facilitate maintenance
The function body that implements member functions within the declaration of a class
This member function automatically becomes an inline function, which is replaced with code wherever it is used in the compilation phase
What the member functions do to differentiate different objects
different objects are distinguished by the this pointer implied by the ordinary member function. The code is shared between different objects of a class, and only the data is different, and the this pointer points to the first address of these different data memory locations.
Use cases for copy constructors
A. When using an object to initialize another object of the same type B. When a function call uses a class object as a formal parameter c. When the function return value returns a class object
When do I have to rewrite the copy constructor
when a member of a class needs to make a deep copy of the pointer, it needs to make dynamic memory allocations within the constructor used, and the corresponding dynamic memory release
within the destructor
Order of constructor calls
A. Calling the constructor of the base class B. Initializing data members of a class in the order in which they are declared c. Calling the class's own constructors
What happens when you have to use the Initialize member list
A. Members of a class have attributes that cannot be modified once initialized the normal property and the reference B. The member of the class is another class, and the class does not have a default constructor (that is, arguments need to be passed)
The meaning of the static member function of the class
compared to ordinary member functions, it is not necessary to generate objects, the cost of the this pointer, and a little more efficient, providing an appropriate implementation for functions that do not need to be instantiated.
What is the way outside the class to access non-common members of a class
friends, inheritance, and public member functions
Abstract class
cannot be used to create an object that can only be used as a base class for inheritance, except that at least one member function is a pure virtual function (declaration = 0, regardless of whether the function has implementation code)
The meaning of operator overloading
Provides a
consistent data manipulation interface for a custom data type with a language built
-in type
5 operators that do not allow overloading
. *,::, sizeof,?:,.
Why can't a stream operator be overloaded with member functions? General how to solve
overloading an operator within a class requires that the first operand of the operator be an object of this class, because the stream object belongs to the class of the standard library and cannot be overloaded with the flow operations of various custom classes in the standard library. Overloading of class flow operators is generally implemented by using the friend function of a custom class
What is the difference between an assignment operator and a copy constructor?
They all build another object of the class from one object of the class, but the copy constructor involves the construction of the object, and the assignment operator does not need to establish the object
When to invoke the function of the destructor of the class
At
the end of the object's life cycle, it is usually near the right curly brace closest to the object
How to share data between objects of a class
implemented by static member variables of a class, static member variables have their own independent storage space, and the data is shared by all members of the entire class and can be accessed.
The order in which the data members of the class are initialized
The order in which
they are initialized is determined by their order in the declaration of the class.
If the virtual function implements polymorphism, is it necessary for the keyword to be overridden in subclasses?
The
virtual keyword is inherited by stealth, even if the subclass does not add this keyword to achieve polymorphism
What is the difference between a function overload and a virtual function in implementing a function's polymorphism?
function overloading is a static polymorphism that is implemented during compilation by different function signatures (number of functions, number of function arguments, type of function arguments), and virtual functions are overridden in subclasses by inheritance relationships between classes and functions
.
Characteristics of a friend relationship
one-way, non-transitive, cannot inherit.
Can constructors and destructors be overloaded?
constructors can have more than one parameter and can be overloaded; destructors can only have one so it cannot be overloaded, and he has no arguments.
Implementation of virtual function
virtual function table (virtual table pointer)???
What code will be executed before the main function executes
The
constructor of the global domain object is executed before the main function executes
When no variables and functions are declared in a class, what is the sizeof class and why?
The
size is 1 to distinguish different objects of a class by assigning different memory addresses to different objects in the program.
The difference between delete and delete[]
Delete Calls only one destructor, which invokes the destructor for each object.
base class and derived class destructors and call order of constructors
During
object creation, the constructor of the base class is called first, then the constructor for the class, and the destructor is called in reverse. In the process of working with the constructor of the base class, the object of this class is not completely established, the information of this class is incomplete, and in the same way, in the process of destruction, the information of this class is destroyed in the process of the destructor work of the base class.
Advantages and disadvantages of inheritance
is a way of code reuse that provides some degree of flexibility, and the benefits are also limited.
When is the constructor and destructor of a class called, and by whom?
are automatically called by the system at the beginning and end of the life cycle of the class, respectively. Sometimes it can be called manually by the programmer.
Pre-compilation
multiple modules, not often changed.
Implementation of polymorphism in C + +
A. Static polymorphism, determined during compilation (function templates and function overloads, note Function default parameters), B. Dynamic polymorphism, determined during runtime (virtual function, overwrite, pointer, or reference)
The role of four characteristics in C + +
encapsulation enables code to be modular, inheritance makes code easy to extend, and polymorphism is for interface consistency and reuse, abstraction??? Concepts of (data abstraction, algorithm abstraction) classes, the concept of templates
Why cannot a normal function, static function, friend function be a virtual function
The
normal function will determine the code at compile time, cannot implement dynamic polymorphism, the static member function of the class has only one copy in the base class and all subclasses, the friend function does not have the inheritance characteristic, also cannot implement the dynamic polymorphism, therefore does not need to support the virtual function
Why an inline function cannot be a virtual function
inline functions are designed to expand code during compilation, and virtual functions are conceptually incompatible in order to support the execution of several different branches of code at run time.
Why a constructor cannot be a virtual function
A. Virtual function implementation requires virtual table support, when the virtual table has not been established B. A constructor cannot be called by a pointer or reference, so it does not have to be set to a virtual function C. The implementation of virtual functions requires a pointer or reference to determine the type of the object, the constructor is called when there is no complete object, cannot determine the object type, so cannot be set to a virtual function.
Why is the destructor of a base class best set to a virtual function?
because dynamic polymorphism supports the use of derived class objects through a base-class pointer or reference, when a derived class object needs to be refactored, only the destructor is a virtual function in order to properly refactor
What functions a private member of a class can be accessed by
can be accessed by member functions and friends of this class
Protected members of a class can be accessed by those functions
can be accessed by the class's member functions and classes derived from the friend and public and protected derivation methods
Frequently cited
both improve the efficiency of the program and protect the data passed to the function is no longer changed in the function
The difference between a pointer and a reference
The reference must be initialized, it cannot be changed after initialization, and pointers do not need to be, pointers can point to null values, references are not allowed.
The expression after switch cannot be a type
can be integer, character, Boolean, enum type, and cannot be considered floating-point data.
How to refer to a defined global variable
A. Global variables within the header file, you can refer to the header file directly after using B. If you define global variables in other source files, you can use the extern keyword with this global variable.
How short functions that are frequently used are handled in the C + + language
Use the
macro definition in the C language to use inline functions in the C + + language.
Three ways to allocate memory
static store allocations are determined during compilation, allocated on the stack, and dynamically allocated on the heap.
What's the use of extern "C"?
used to declare a specific program statement or block of statements in a C + + program as compiled by the C-language function naming convention.
What is the difference between defining constants using # define and const
#define是C语言预处理器的语法关键字, only constant substitution is performed during compilation; Const is the C + + language's method of defining a constant variable, it has a type, has memory allocations, and can be used to test the length with sizeof.
The difference between struct and class
The
default inbound property for struct members is public, while class's default inbound property is private.
Can local variables and global variables have the same name?
Yes, the local variable will mask the global variable; you need to access the global variable using:: Domain operator.
ASSERT macro
used to debug programs to avoid significant errors or illegal data in the program, which can be used #define NDEBUG to prohibit assert assertions in a specific version of a program
What parts of Windows Message Queuing are made up of
A. System Message Queuing, which is the responsibility of the operating system to deliver messages to a particular application's message Queue B. Application message loops, each application has its own message queue, and in the application message loop, continuously extracts messages from its own message queue and processes specific messages. The message is then referred to the Windows operating system to invoke the appropriate window handler. The window handler function, in addition to the messages that have been processed in the message loop, will be called by the operating system to handle the different messages.
What's the difference between SendMessage and postmessage?
SendMessage is the process of skipping Message Queuing and message loops directly to a particular window handler and waiting for the end of the message processing to be returned. PostMessage is to put the message in the application message queue, but does not wait for the message to end but returns immediately.
Message map
in MFC classes, programmers implement various processing of MFC class-to-operating system messages by mapping system messages to member functions of classes.
What are the three dynamic link libraries that make up the Win32 API?
Kernel32.dll, User32.dll and Gdi32.dll
Windows messages are categorized into categories and are briefly described for each class?
A. Window messages: Messages related to Windows, except WM_COMMAND for b. Command messages: A message for handling user requests to WM_COMMAND represent C. Control notification message: Unified by WM_NOTIFY Representation D. User-defined message
How Windows customizes messages
using WM_USER and WM_APP customizing messages
How to eliminate ambiguity in multiple inheritance
A. Using the Member qualifier B. Using the virtual base class
Conditions for run-time polymorphism
A. Inheritance B. Base class virtual functions are overridden in subclasses c. Use a base-class pointer or reference to point to a child-class object
The class from which most of the classes in MFC inherit
CObject class->ccmdtarget class
The differences between C + + class member functions overloading, overwriting, and hiding
An
overloaded condition (3), a relationship between a function of the same name in a base class and a derived class, is a hidden relationship except for overrides. Overridden condition (a function with the same name as the parent-child class with an inheritance relationship, if the parameter is the same, the return value is covariant and the base class function has the virtual keyword, then the function of the same name forms an overlay relationship).
How to print out the filename and line number of the current source file
__FILE__ and __LINE__ the

Author:mashomee

Created:2015-03-10 Tue 20:05

Emacs 24.4.1 (ORG mode 8.2.10)

Validate

A collection of test questions for C + + (I.)

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.