The TORCS Racing Board
Username: Password: Remember Me?
Lost Password Register
Author: dummy | Created: 2017-09-12 08:21:41
Subject: Mouse compile error
Stuck.cpp: In member function ‘void Stuck::fillTrackCells(const MyTrack&)’:
Stuck.cpp:885:13: error: invalid initialization of non-const reference of type ‘std::vector<Stuck::Edge>&’ from an rvalue of type ‘std::vector<Stuck::Edge>’
In file included from /usr/include/c++/6/vector:64:0,
from /usr/include/c++/6/queue:61,
from Stuck.cpp:1:
/usr/include/c++/6/bits/stl_vector.h:1195:7: note: initializing argument 1 of ‘void std::vector<_Tp, _Alloc>::swap(std::vector<_Tp, _Alloc>&) [with _Tp = Stuck::Edge; _Alloc = std::allocator<Stuck::Edge>]’
swap(vector& __x) _GLIBCXX_NOEXCEPT
Last Edited: 2017-09-12 08:23:57 by dummy
    Author: timfoden | Created: 2017-09-12 09:08:03
    Subject: Re: Mouse compile error

    The point of doing this swap is to both clear the row vector and free up its memory. It's a fairly well known idiom as "row.resize(0);" isn't guaranteed to free the memory in earlier versions of the C++ standard.

    Change this non-working line:


    To this instead:


    And if that doesn't work for you, just simply:

    row.resize(0); // and live with the possible non-deallocation of the memory.

    Cheers, Tim.
    Last Edited: 2017-09-12 09:08:03 by timfoden
      Author: dummy | Created: 2017-09-12 10:39:39
      Subject: Re: Mouse compile error
      Thanks a lot Tim!
      vector<Edge>().swap(row) works.

      Also I had to add this to Stuck.cpp because of another error:
      #include <algorithm>
      Last Edited: 2017-09-12 10:39:39 by dummy