error: passing ‘const std::string‘ as ‘this‘ argument of

error: passing ‘const std::string’ as ‘this’ argument of ‘std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits, _Alloc = std::allocator]’ discards qualifiers

//回調函數
void DealWithResponseThread::deliveryMsg(const std::string& topic, const char * key, size_t key_len, const char* msg, size_t msg_len, int64_t msg_offset, int32_t msg_partition) const
{
	string s(msg);
	this->m_strCallBackJson = s;
}

上面的程序在編譯的時候,遇到上面的錯誤,原因是這個成員函數是隻讀函數(函數後面有const修飾),我對成員變量進行了賦值,所以報錯。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章