0
我想要在C++中使用自定义标量对象来获取STL地图,以便我可以在OpenCV的地图中使用标量类。我收到以下错误:在地图抛出错误的C++自定义对象
error: ‘template class std::map’ used without template parameters
,这是使用模板IM:
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
失败在我f声明,我无法弄清楚为什么?
你为什么认为'std :: map :: end'可以工作?另外,请阅读[有关在C++标识符中使用下划线的规则?](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in- AC-标识符)。 –
这很有趣,你说下划线的东西,我只是跟着OpenCV中的C++ api做什么! – L7ColWinters
那么,唯一可以返回的东西是使用'()'的函数,因为'end()'是一个非静态成员函数,所以你需要在实例上调用它。另外请注意,并非所有的下划线都是禁止的,在你的情况下'_Tp','MyScalar_'和'Scalar_'是禁止的。 –