Chapter 9 Memory Model and Namespaces

1. Header file

1. Function prototype

2. Symbolic constants defined using #define and const

3. Structural declaration

4. Class declaration

5. Template declaration

6. Inline functions

2. Linkability of static storage

external, internal, none

3. get() reads empty line false

get(char*,int) reads an empty line and causes cin to be false

4. Const constants are placed in header files

The constant declared by const is internally linked; each file that references the header file will have a const constant

5. Locating the new operator

//从buffer1内分配出内存空间,但是不能手动释放
//因为此时的buffer1并不在delete的管辖范围内
char buffer1[500];
int* p1 = new(buffer1) int [20];

//此时的buffer2的内存可以释放
char* buffer2 = new char[50];
char* p2 = new (buffer2) char[20];
delete p2;//但这样操作不被允许。
//原因:delete和常规new运算符搭配使用,但是不能和定位new运算符搭配。

 6. The new operator can be overloaded

The content in 5 shows that the new operator has been overloaded

7. using declaration and using compilation

namespace jill{

    int ftech;
    double test(){
        cout<<"test:"<<endl;
    }
}
char fetch;
int main(){
    using fill::fetch;
    double fetch;//不允许
    cout<<fetch;
}
namespace jill{
    int ftech;
    double test(){
        cout<<"test:"<<endl;
    }
}
char fetch;
int main(){
    using fill;
    double fetch;//允许
    cout<<fetch<<endl;//局部的fetch
    cout<<fill::fetch<<endl;
    cout<<::fetch<<endl;//全局的fetch
}

Guess you like

Origin blog.csdn.net/qq_42813620/article/details/130793524