K
Kei
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!
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!