我真的很困惑,爲什麼我得到以下編譯錯誤。 Microsoft Visual Studio編譯器。錯誤C2678:二進制'=':找不到操作符,它需要類型'const std :: string'的左手操作數(或沒有可接受的轉換)
error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion)
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iterator>
class MyException {
public:
MyException( std::string message,
int line = 0) : m_message(message),
m_line(line) {}
const char* what() const throw(){
if (m_line != 0) {
std::ostringstream custom_message;
custom_message << "Parsing Error occured at ";
custom_message << m_line << " Line : ";
custom_message << m_message;
m_message = custom_message.str();
}
return m_message.c_str();
}
private:
std::string m_message;
int m_line;
};
int main(int argc, char **argv) {
try {
// do something
}catch(MyException &e){
std::cout << e.what();
}
}
誤差在行 m_message = custom_message.str();
你錯過頭'',這可能佔行爲。 –
templatetypedef