I have a class
class MyClass {
public:
string name;
};
I have a class manager, with a vector of said classes.
class MyManager {
public:
vector<MyClass> classes;
};
I want to pull out a class from the vector by looping and matching with the name
int MyManager::FindMyClass(string name, MyClass *clazz){
vector<MyClass>::iterator it;
for(it = classes.begin(); it != classes.end(); ++it){
if(it->name == name){
// if i cout here, i see the cout, so i did find it..
*clazz = *it;
return 1;
}
}
return 0;
}
int main() {
MyClass *myClass;
int result = myManager.FindMyClass("bob", *myClass);
}
I know for a fact that the object is matched properly (see the comment). I've tried every combination of pointers, double pointers, references, and get every error from unknown conversions to invalid pointers. I am just not sure what I have to do to get a reference to the class stored in the vector.