0

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);

1
  • 3
    So, when you tried this, what did you learn? Commented Feb 3, 2014 at 6:15

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

std::string already has a constructor to handle this. std::string s2("hill") will work without any problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.