Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
adding search capability to a Vector
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Kei, post: 3790669"] Hello, I am trying to add a simple search behaviour to a STL Vector like the following: //---- declaration --- typedef struct { std::string name; std::string favouriteFood; } TBuddy; typedef TBuddy* PBuddy; class TBuddies: public std::vector<PBuddy> { public: std::string favouriteFoodOf(const std::string& name) const; }; //---- implementation --- std::string TBuddies::findValue(const std::string& name) const { for(TBuddies::iterator i= this->begin(); i!= this->end(); ++i) { PBuddy b = *i; if(b->name ==s) return b->favouriteFood; } return ""; } But it couldn't compile... There is a strange error saying "Invalid conversion from TBuddy const* const to TBuddy**". But the "const" keyword in the function is required. Somehow, is the iterator trying to modify the instance ? Thanks! [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
adding search capability to a Vector
Top