M
matobinder
Probably a simple problem here. I fairly new to STL, but getting to like
its features.
I have a vector of objects, due to nature of the objects, I need to have it
be a vector of pointers. I am handling the deallocation of those
objects myself.
So my problem is, lets say I have:
vector<MyClass*> thisGuy;
MyClass has a member function that returns a std::string, lets call
it MyClass::getName()
I am trying to do something like the following(assume getName really
returns joeblow).
if ( thisGuy.at(1)->getName() == "joeblow")
This compiles, but doesn't work as I expect, it always yeilds true, even
when it is not.
But if I do:
std::string buf = thisGuy.at(1)->getName();
if ( buf == "joeblow" )
This works as I expect. buf definitely is "joeblow".
Anyways, is there a way I can do the above comparison, without needing
to have the temporary std::string buf?
-mato
its features.
I have a vector of objects, due to nature of the objects, I need to have it
be a vector of pointers. I am handling the deallocation of those
objects myself.
So my problem is, lets say I have:
vector<MyClass*> thisGuy;
MyClass has a member function that returns a std::string, lets call
it MyClass::getName()
I am trying to do something like the following(assume getName really
returns joeblow).
if ( thisGuy.at(1)->getName() == "joeblow")
This compiles, but doesn't work as I expect, it always yeilds true, even
when it is not.
But if I do:
std::string buf = thisGuy.at(1)->getName();
if ( buf == "joeblow" )
This works as I expect. buf definitely is "joeblow".
Anyways, is there a way I can do the above comparison, without needing
to have the temporary std::string buf?
-mato