Given the following code,
class A
{
public:
A() : str(0) {}
private:
string str;
};
Based on this http://www.cplusplus.com/reference/string/string/string/
string ( );
string ( const string& str );
string ( const string& str, size_t pos, size_t n = npos );
string ( const char * s, size_t n );
string ( const char * s );
string ( size_t n, char c );
template<class InputIterator> string (InputIterator begin, InputIterator end);
I don't see which constructor of string is called when we use the 'str(0)'.
Question> Can someone tell me which string constructor is used for 'str(0)'?
This one:
string ( const char * s );
It's converted to a null pointer. (And also gives you undefined behavior, since s cannot be a null pointer.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With