0

我正在尝试在 C++ 中使用自定义标量对象获取 STL 映射,以便我可以在 OpenCV 的映射中使用标量类。我收到以下错误:

error: ‘template class std::map’ used without template parameters

这是我使用的模板:

template<typename _Tp> class MyScalar_ : public Scalar_<_Tp>{
public:
    MyScalar_();
    MyScalar_(Scalar_<_Tp>& s){
        _s = s;
    };
    _Tp& operator[](const int idx){
        return _s[idx];
    }
    //std::less<_Tp>::operator()(const _Tp&, const _Tp&) const
    //this wont work if scalars are using doubles
    bool operator < (const MyScalar_<_Tp>& obj) const {
        double lhs,rhs;
        lhs = _s[0] + _s[1] + _s[2] + _s[3];
        rhs = _s[0] + _s[1] + _s[2] + _s[3];
        return lhs > rhs;
    }
    bool operator == (const MyScalar_<_Tp>& obj) const{
        bool valid = true;
        for(int i = 0;i<_s.size();i++){
            if(_s[i] != obj[i])
                return false;
        }
        return valid;
    }
    private:
        Scalar_<_Tp> _s;
};

std::map< MyScalar,Point > edgeColorMap;的头文件中也有

上面的错误表明该行:

auto tempit = edgeColorMap.find(s);
    if(tempit != std::map::end){//found a color that this pixel relates to

if 语句失败,我不知道为什么?

4

1 回答 1

1

您需要使用来自实际map实例的迭代器:

if(tempit != edgeColorMap.end()) {

std::map::end()只是一个普通函数,它返回一个迭代器或 const_iterator 到容器最后一个元素之后的元素。

于 2012-11-15T23:37:52.157 回答