std::map的使用

刚刚想写个接口

class XXX;

class YYY

{

typedef std::map<string, XXX*> XXXList;

XXXList mXXXNodes;

XXX* getXXXNode(const std::string zzz) const

{

    。。。

    if (NULL == mXXXNodes[zzz];
    。。。

}

};


报错提示:error C2678: binary '[' : no operator found which takes a left-hand operand of type 'const SceneManager::SceneNodeMap' (or there is no acceptable conversion)
1>        d:\program files\microsoft visual studio 8\vc\include\map(166): could be 'SceneNode *&std::map<_Kty,_Ty>::operator [](const std::basic_string<_Elem,_Traits,_Ax> &)'
1>        with
1>        [
1>            _Kty=std::string,
1>            _Ty=SceneNode *,
1>            _Elem=char,
1>            _Traits=std::char_traits<char>,
1>            _Ax=std::allocator<char>
1>        ]
1>        while trying to match the argument list '(const SceneManager::SceneNodeMap, const std::string)'

也就是说,std::map没有重载const 参数的operator[]运算符,自己肯定不会去重载std::map的operator操作,也不愿意将接口改变为

XXX* getXXXNode(const std::string zzz)

修改的方法:其实可以用
SceneNodeMap::const_iterator i = mSceneNodes.find(pName);

    if (i == mSceneNodes.end())
        // 找不到该名字的节点
        return NULL;

    return i->second;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值