Skip to main content
gamedev.net
🔒 Locked

STL C++: iterator issue

Started by Alessandro 5 replies 1.7k views
Original Post
Alessandro
Alessandro

Hi folks,

I'm trying to search a std::vector declared like this:


std::vector<MyItem*> myNodeContainer;

where MyItem is looking like this:


class MyItem :public QGraphicsItem
{
public:
    MyItem(QString QwNodeType, QString iQwFamilyType);
    int testID;
...

Now, I've built a function to search the testID:


struct findNodeUUID2 {
	findNodeUUID2(int i) : id(i) { }
	bool operator()(const MyItem* &obj) { return (obj->testID==id); }
	int id;
};

and I try to search like this:


    std::vector<MyItem*>::iterator findNodeIterator;
    findNodeIterator=std::find_if(myNodeContainer.begin(),myNodeContainer.end(), findNodeUUID2(1234) );

Linker errors as follows:

stl_algo.h.... No matching function for call to object of type 'findNodeUUID2'

What am I doing wrong? I suppose I'm using pointers the wrong way? Thanks for any suggestion

Chris_F
Chris_F

Why not use a lambda function instead? Even Visual Studio supports that.


auto findNodeIterator = std::find_if(myNodeContainer.begin(), myNodeContainer.end(), [](const MyItem* obj) { return obj->testID == 1234; });
BitMaster
BitMaster
My experience with XCode is limited but shouldn't XCode default to Clang and Clang supports all/most of the new C++11/C++14 stuff?
jwezorek
jwezorek

Hi Chris, can't do that since I need to compile on XCode too...

Xcode has supported lambdas since about version 4.5, see here. However, I believe these and other C++11 features are still not enabled by default -- at least they didn't used to be.

Go to build settings and look for an item called "C++ Language Dialect". You need to select C++11 or greater.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.