Linux 错误(Klocwork):&x27_M_dataplus._M_p';可能在未初始化的情况下在此函数中使用
'Klocwork'profiller在下面的代码部分中生成错误['it.second.name.\u M\u dataplus.\u M\u p'可能未初始化就用于此函数。]Linux 错误(Klocwork):&x27_M_dataplus._M_p';可能在未初始化的情况下在此函数中使用,linux,c++11,stl,Linux,C++11,Stl,'Klocwork'profiller在下面的代码部分中生成错误['it.second.name.\u M\u dataplus.\u M\u p'可能未初始化就用于此函数。] class Test { public: Test() { } Test(std::string str) { name = str;
class Test {
public:
Test() { }
Test(std::string str) {
name = str;
cout <<"Test::Test object: " <<name <<endl;
}
~Test() {
cout <<"Test::~Test object: " <<name <<endl;
}
string getName() {
return name;
}
private:
string name;
};
class MapHandler {
private:
map<int, Test> myMap;
public:
void MapFiller();
void MapDisplay();
};
void MapHandler::MapFiller() {
Test obj1("Obj1");
Test obj2("Obj2");
Test obj3("Obj3");
myMap[1] = obj1;
myMap[2] = obj1;
myMap[3] = obj3;
}
void MapHandler::MapDisplay() {
map<int, Test> tmpMap;
for(auto it : myMap) {
cout <<"object: " << it.second.getName() <<endl;
tmpMap[it.first] = it.second;
} **//Error Line**
}
类测试{
公众:
Test(){}
测试(标准::字符串str){
name=str;
无法尝试更改默认构造函数:
Test()
{
name = "";
}