Programmerzzz
Programmerzzz

Reputation: 1287

iterate over a vector thats defined as a typedef C++

I have a struct as follows

struct pins
{
    PType pintypes;
    GType Grouptypes
};

where PType and GType are defined as

typedef std::vector< pInfo > PType;
typedef std::vector<gInfo> GType;

where pInfo and gInfo are classes with sample members as

struct pInfo {
    std::string pinNumber;
    std::string pinName;
};

Now I am comparing two PinInfos from pins variable.I want to see if given two pins, they have exactly the same pintypes.

I am trying as follows.

for (std::vector<pInfo>::const_iterator prim1Pin = pins.pinTypes.begin(); prim1Pin != pins.pinTypes.end(); prim1Pin++)
    {
        if (bRet)
        {
            std::vector<pInfo>::const_iterator prim2pin = std::find(prim2.pinTypes.begin(), prim2.pinTypes.end(), (*prim1Pin).pinNumber);
            if (prim2pin!=prim2.pinTypes.end())
            {
                bRet &= ((*prim2pin).PinNumber== (*prim1Pin).PinNumber&& (*prim2pin).pinName == (*prim1Pin).pinName)                    
            }
            else
                bRet &= false;
        }
    }

when I compile this I get the following error in algorithm.h file

Error C2678 binary '==' : no operator found which takes a left-hand operand of type 'pInfo' (or there is no acceptable conversion) C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\algorithm 41 Not sure whats wrong with this. I am using some version less than C++ 11.

Upvotes: 0

Views: 130

Answers (1)

1201ProgramAlarm
1201ProgramAlarm

Reputation: 32717

In your call to find, you're iterating over a container that holds a bunch of pinType objects, while you're searching for a string value. The compiler will need an overload of operator== that takes a pinType on the left and a string on the right.

So you'll want to either provide that operation, or define a lambda or comparison class to handle it.

Upvotes: 2

Related Questions