C ++ written Frequently Asked Questions

C ++ preprocessor functionality provided mainly in the following three ways:

  • Macro definition
  • File contains
  • Conditional compilation

Also known as pre-pre-compiled, the code is the replacement text of work to do. Processing #instruction at the beginning, such as copies of #includefile code contained #definereplace macro definition, conditional compilation, etc., is the stage for the compiler to do the preparatory work, the pre-compiler directives mainly deal with # the beginning of the pre-compiler directive indicates before the program officially compiled it is performed by the operation of the compiler, any point in the program can be placed.
Preprocessing instruction is the beginning of the line number #. #The line number must be in addition to any blank characters first character. #After the command is a keyword, keywords, and between # Number allows any number of white character exists. Entire line statement constitute a preprocessing instructions that will make some compiler converts the source code prior to the compiler.

Here are some preprocessing directives:

    指令             用途
        #           空指令,无任何效果
        #include    包含一个源代码文件
        #define     定义宏
        #undef      取消已定义的宏
        #if         如果给定条件为真,则编译下面代码
        #ifdef      如果宏已经定义,则编译下面代码
        #ifndef     如果宏没有定义,则编译下面代码
        #elif       如果前面的#if给定条件不为真,当前条件为真,则编译下面代码
        #endif      结束一个#if……#else条件编译块
        #error      停止编译并显示错误信息

Pre-compiled in C ++

const constant define the difference between macro definition

1. Different compilers treatment. define宏In the pre-processing stage is to start the life cycle beyond the compile time. Just a constant, a command parameter, no actual existence. #defineConstants present in the program code segments. const常量Is compiled using the operational phase, const常量present in the program data segment.
2. The different types and security checks. define宏No type, do not do any type checking, just start. const常量There are specific types, will perform at compile time type checking.
3. Storage of different ways. define宏Just a start, how many places, how many times had begun, does not allocate memory. const常量Will be allocated in memory (can be a heap may also be a stack)

#include <my.h>with#include "my.h"

1. The first method ( #include <my.h>) is a header file enclosed in angle brackets. This format tells the preprocessor searches for header files are included in the header file that comes with the compiler or an external library. The second method ( #include "my.h") is a header file enclosed in double quotes. This format tells the preprocessor searches for header files are included in the source code file is currently being compiled application, if not, then search the compiler that comes with header files.

2. The grounds contain two different formats is that the compiler is installed in the public subdirectory, and was compiled application under their own private subdirectory. An application that contains both public header file provided with the compiler, header files also contain private custom. Two different formats comprising a compiler to distinguish such a set of header files in many common header files

In short, #include <my.h>starting from the standard library search path in the file, #include "my.h"the compiler starts working path users to search for files


The three basic features of object-oriented design principles and five kinds of

Three basic characteristics

1. Package (Encapsulation)

The so-called package, which is the objective things packaged as an abstract class, and the class can put their data and methods allow only trusted class or object manipulation, hiding on untrusted information.

2. Inheritance (Inheritance)

Inheritance refers to such a capability: it can use all the features of an existing class, and without having to rewrite these functions extend the case of the original class.

3. polymorphism (Polymorphism)

Polymorphism refers to the so-called method of the same instance of a class have different forms in different situations. Of polymorphism so that objects having different internal structures can share the same external interface.

Five design principles

1. Single Responsibility Principle (Single-Resposibility Principle)

It should only be one reason for a class changes caused by it

2. Open Closed Principle (Open-Closed principle)

Extended is open to change is closed!

3.) Richter substitution principle (Liskov-Substituion Principle)

Subclass can replace the parent class and any place can appear in the parent class appears, carry out advocacy-oriented programming interface GOF

4. Dependency Inversion Principle (Dependecy-Inversion Principle)

Traditional structured programming, top-level modules usually have to rely on the following sub-modules to achieve, also known as low-level executives rely on! So DIP principle is to reverse this dependency, so do not rely on the lower level module module, so called Dependency Inversion Principle!

5.ISP Interface segregation principle (Interface-Segregation Principle)

Using multiple specialized interface is much better than using a single interface!

Object-oriented features of the three, the five principles of
object-oriented design principles and three basic features five kinds

Why is the size of an empty class 1

Standard prohibits the object size is 0, since two different objects require different address indicates

Why empty class size is 1?

Long-term update

Guess you like

Origin www.cnblogs.com/clwsec/p/11515508.html