How do I resolve: "error C2039: 'cstr' : is not a member of 'std::basic_string"?
#include <stdexcept>
#include <string>
using namespace std;
class ListIndexOutOfRangeException : public out_of_range
{
public:
ListIndexOutOfRangeException(const string & message = "") : out开发者_运维技巧_of_range(message.c_str())
{
}
}; // end ListIndexOutOfRangeException
out_of_range
accepts a string reference, so just use
: out_of_range(message)
instead.
edit:
And as others have said, the compiler is telling you you have used message.cstr()
instead of message.c_str()
. But the method call is unnecessary anyway, just pass the string.
精彩评论