0

I'm trying to get a STL map in C++ working with custom scalar objects so that I can use the scalar class in a map for OpenCV. I'm getting the following error:

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

and this is the template im using:

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;
};

I have std::map< MyScalar,Point > edgeColorMap; in my header file as well

the error above states that the line:

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

fails at the if statement and I can't figure out why??

L7ColWinters
  • 1,342
  • 1
  • 14
  • 31
  • Why did you think `std::map::end` would work? Also, please read [What are the rules about using an underscore in a C++ identifier?](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier). – Jesse Good Nov 15 '12 at 23:38
  • that's interesting that you say the underscore thing, I'm just following what the c++ api in OpenCV was doing! – L7ColWinters Nov 15 '12 at 23:42
  • 1
    Well, the only thing that can return things are functions which use `()`, and since `end()` is a non-static member function you need to call it on an instance. Also, note that not all underscores are prohibited, in your case `_Tp`, `MyScalar_` and `Scalar_` would be the prohibited ones. – Jesse Good Nov 15 '12 at 23:49
  • Yeah from the webpage it looked like it would have been a static variable... but take a look at this http://opencv.willowgarage.com/documentation/cpp/basic_structures.htmlso your saying that there not following standards – L7ColWinters Nov 15 '12 at 23:53
  • That link you posted seems to be dead. I've never used OpenCV, but I found a couple bug reports about name collisions because they do not follow the standard, [see here](http://code.opencv.org/issues/221) and [here](https://code.ros.org/trac/opencv/ticket/218). This is what happens when you do not follow the standard. – Jesse Good Nov 16 '12 at 00:01
  • http://opencv.willowgarage.com/documentation/cpp/basic_structures.html it added an so to the end of it for some reason. Thanks for the heads up! – L7ColWinters Nov 16 '12 at 00:03

1 Answers1

1

You need to use an iterator from the actual map instance:

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

std::map::end() is just a normal function which returns an iterator or const_iterator to the element following the last element of the container.

Fraser
  • 74,704
  • 20
  • 238
  • 215