Reputation: 747
String s2("hi");
Do I have to write an implicit string constructor
String::String(const char* str);
or
would this constructor handle it:
String::String(const String &str);
Upvotes: 0
Views: 267
Reputation: 851
When you create this string object, string (const char* s) constructor will be called, so there is a no need of writing a constructor.
Here are the constructors which are defined inside the std::string class
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);
Further don't try to edit some standard libraries, It will lead to unwanted issues. if you want any customized functions, write a wrapper of your own.
Upvotes: 1
Reputation: 653
std::string already has a constructor to handle this. std::string s2("hill") will work without any problem.
Upvotes: 0