I feel like I should understand this stuff by now... =/
Anyway, lets say I have a class:
class someClass
{
private:
std::vector<Thing> myVector;
public:
std::vector<Thing>& getThings(); //simply returns myVector
};
Now, lets say that I have another class which contains an instance of someClass. It has a method whose goal it is to get myVector, iterate through it and pull out some subset of the Things contained in it based on some criteria. It wants to take that subset and put references (preferably) to those Things in a new vector which it will, itself, control. This was my attempt at that (minus a lot of the details), and it definitely isn't storing references:
std::vector<Thing> otherVector; //Assume these are private data members in the class
someClass myClass; //HigherClass
void HigherClass::doesSomeThings()
{
std::vector<Thing> &tempVector = myClass.getThings()
//tempVector should be the same as myVector in myClass, yes? Like tempVector is
//another name for myVector?
for(unsigned int i = 0; i < tempVector.size(); i++)
{
if(***some random condition is met***)
{
Thing &myThing = tempVector;
//again, myThing should now be an alternate name for the Thing contained at
//tempVector, no?
otherVector.push_back(myThing);
}
}
}
So... where am I going wrong?
EDIT: Fixed Formatting
EDIT again: AAAARRGGGHH apparently you just can't store references in a container like this... which makes perfect sense for very obvious reasons and I'm just an idiot. Someone tell me that my logic at least is correct if this code was for some mythical language that allowed references to be stored in containers. :)