: allocator(_Al) {_Tidy(); }
basic_string(const _Myt& _X)
: allocator(_X.allocator)
{_Tidy(), assign(_X, 0, npos); }
basic_string(const _Myt& _X, size_type _P, size_type _M,
const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_X, _P, _M); }
basic_string(const _E *_S, size_type _N,
const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_S, _N); }
basic_string(const _E *_S, const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_S); }
basic_string(size_type _N, _E _C, const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_N, _C); }
explicit basic_string(const _A& _Al = _A())
: allocator(_Al) {_Tidy(); }
basic_string(const _Myt& _X)
: allocator(_X.allocator)
{_Tidy(), assign(_X, 0, npos); }
basic_string(const _Myt& _X, size_type _P, size_type _M,
const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_X, _P, _M); }
basic_string(const _E *_S, size_type _N,
const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_S, _N); }
basic_string(const _E *_S, const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_S); }
basic_string(size_type _N, _E _C, const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_N, _C); }其实重要的是第一个构造函数,因为此处调用就是它,给basic_string分配一个内存分配管理器:)
明白了吧,此处有是因为类里面有一个string类的对象,别人属于你,别人有自已的构造函数,需要为其赋一个初始值,你总不能不让吧,于是编译器就合成一个默认的构造函数,调用string里的构造函数,为string对像置一个初始状态
构造函数的确是不一定会有的,而且类里的一些内置类型默认构造函数也不会给其设定一个默认值的,不信你再看看汇编,哪里有对ptr的赋值:)
有四种情况编译器会为合成默认构造函数
1:含有默认默认/构造函数的成员类对象
2:带有默认/构造函数的基类对象
3: 含有虚函数的类
4:继承虚基类的类