Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;映射/集合迭代器不可取消引用--map<;常量字符*,字符串>; A类 { 公众: map strs;//它在函数中初始化 地图我的地图; 虚拟void setMyMap() { insert({str.begin()->first.c_str(),“aaa”}); } }; B类:公共A类 {}; 丙类:公共乙类 { 虚拟void setMyMap() { B::setMyMap(); for(auto it=myMap.begin();it!=myMap.end();++it) { cout first_C++_Dictionary - Fatal编程技术网

C++ c++;映射/集合迭代器不可取消引用--map<;常量字符*,字符串>; A类 { 公众: map strs;//它在函数中初始化 地图我的地图; 虚拟void setMyMap() { insert({str.begin()->first.c_str(),“aaa”}); } }; B类:公共A类 {}; 丙类:公共乙类 { 虚拟void setMyMap() { B::setMyMap(); for(auto it=myMap.begin();it!=myMap.end();++it) { cout first

C++ c++;映射/集合迭代器不可取消引用--map<;常量字符*,字符串>; A类 { 公众: map strs;//它在函数中初始化 地图我的地图; 虚拟void setMyMap() { insert({str.begin()->first.c_str(),“aaa”}); } }; B类:公共A类 {}; 丙类:公共乙类 { 虚拟void setMyMap() { B::setMyMap(); for(auto it=myMap.begin();it!=myMap.end();++it) { cout first,c++,dictionary,C++,Dictionary,一个带有const char*的映射,因为它们键不比较字符串,只比较指针地址。两个字符串“A”不同地址的比较不相等。必须使用std::string或自定义比较函数。不要假设字符串文本的地址。是因为我插入了str.begin()->first.c_str(),这可能是一个临时变量吗? class A { public: map<string, string> strs; // it's initialized in a function map<const cha

一个带有
const char*
的映射,因为它们键不比较字符串,只比较指针地址。两个字符串
“A”不同地址的
比较不相等。必须使用
std::string
或自定义比较函数。不要假设字符串文本的地址。

是因为我插入了
str.begin()->first.c_str()
,这可能是一个临时变量吗?
class A
{
public:
    map<string, string> strs; // it's initialized in a function
    map<const char *, string> myMap;
    virtual void setMyMap()
    {
        myMap.insert({str.begin()->first.c_str(), "aaa"});
    }
};

class B : public class A
{};

class C : public class B
{
    virtual void setMyMap()
    {
        B::setMyMap();
        for (auto it = myMap.begin(); it != myMap.end(); ++it)
        {
            cout << it->first << std::endl; // "a"
        }
        cout<<(myMap.find("a") == myMap.end()); // 1
        myMap.find("a")->first; // get the error
    }
};