C++ 字符串类的隐式构造函数

C++ 字符串类的隐式构造函数,c++,class-constructors,C++,Class Constructors,字符串s2(“hi”) 我必须写一个隐式字符串构造函数吗 字符串::字符串(const char*str) 或 这个构造器会处理它吗: 字符串::字符串(常量字符串和str) std::string已经有了一个构造函数来处理这个问题。字符串s2(“hill”)将正常工作 创建此string对象时,将调用string(const char*s)构造函数,因此无需编写构造函数 以下是在std::string类中定义的构造函数 string(); string (const string&

字符串s2(“hi”)

我必须写一个隐式字符串构造函数吗

字符串::字符串(const char*str)

这个构造器会处理它吗:


字符串::字符串(常量字符串和str)

std::string已经有了一个构造函数来处理这个问题。字符串s2(“hill”)将正常工作

创建此string对象时,将调用string(const char*s)构造函数,因此无需编写构造函数

以下是在std::string类中定义的构造函数

string();   
string (const string& str); 
string (const string& str, size_t pos, size_t len = npos);  
string (const char* s); 
string (const char* s, size_t n);   
string (size_t n, char c);  
template <class InputIterator>
  string  (InputIterator first, InputIterator last);
string();
字符串(常量字符串和str);
字符串(常量字符串和字符串、大小位置、大小长度=npos);
字符串(常量字符*s);
字符串(常量字符*s,大小\u t n);
字符串(大小n,字符c);
模板
字符串(先输入位,后输入位);

此外,不要试图编辑一些标准库,这将导致不必要的问题。如果您想要自定义函数,请编写自己的包装器。

那么,当您尝试此功能时,您学到了什么?