#Passing by reference doesn't pass by reference?

12 messages · Page 1 of 1 (latest)

plucky kiteBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

mental tundra
#

white are the original ones and green are the updated ones

#

the whites dont at all

limber estuary
#

You're creating a new list of particles

mental tundra
#

yes but im emplacing into it the refrence of the particles from the first list arent i?

#
for (T& element : points) {
        found.emplace_back(element);
}
#

like this

#

doesnt this copy by reference instead of value?

limber estuary
#

It creates a copy either way

mental tundra
#

then how can i get all the points by reference?

#
template <typename T>
class Quadtree {
public:
    Quadtree(Rectangle b, int c) : boundary(b), capacity(c), ne(nullptr), nw(nullptr), se(nullptr), sw(nullptr) {
        static_assert(std::is_base_of<Point, T>::value, "Not derived from Base.");
    }
    list<T> getPoints() {
        list<T> found;
        found.insert(found.end(), points.begin(), points.end());
        if (divided) {
            list<T> returned_found = ne->getPoints();
            found.insert(found.end(), returned_found.begin(), returned_found.end());
            returned_found = nw->getPoints();
            found.insert(found.end(), returned_found.begin(), returned_found.end());
            returned_found = se->getPoints();
            found.insert(found.end(), returned_found.begin(), returned_found.end());
            returned_found = sw->getPoints();
            found.insert(found.end(), returned_found.begin(), returned_found.end());
        }
        return found;
private:
    list<T> points;
    Rectangle boundary;
    int capacity;
    Quadtree* ne;
    Quadtree* nw;
    Quadtree* se;
    Quadtree* sw;
    bool divided = false;
};

basically this is my class, and i want to go down the quadtree to get all the points by reference.

mental tundra
#

anyone here?