Std::vector from another class - Push back desont add anything

Std::vector from another class - Push back desont add anything
0.0 0


Hi - Another issue - i cant even think of key words to search google to try find solution

m_GSelected is a GGroup* class which has a std::vector<GBody*> m_GBodies;


std::vector<GBody*> getBodies() { return m_GBodies; };


Why does this not add anything to the vector. I use the debugging tool in Visual Studio, to walk through it and everything is fine and nothing gets added. Vector stays empty size 0

I am using work around like so

std::vector<GBody*> m_PlaceholderBodies = m_GSelected->getBodies();
m_GSelected->setBodies(m_PlaceholderBodies );

This works

Thanks for any pointers that you may have to this issue :slight_smile:


std::vector<GBody*> getBodies() { return m_GBodies; }; Returns a copy of m_GBodies. You need to return a pointer or reference. Try: std::vector<GBody*>& getBodies() { return m_GBodies; };

You may want to look into references in C++.


I am a noob ! Yes this makes perfect sense now… :slight_smile:
I need watch some videos on pointers and references as it still doesn’t sit well in my soul

Ill try this later