mercredi 27 novembre 2019

std::list push_back() and pop_front() giving a const error

I am working on a coding project and have hit a bit of a snag. When I try to make it, I get these errors:

src/mean.cc:26:12: error: passing ‘const csce240::Mean’ as ‘this’ argument discards qualifiers [-fpermissive]
   pop_back();
            ^
In file included from /usr/include/c++/7/list:63:0,
                 from inc/mean.h:9,
                 from src/mean.cc:2:
/usr/include/c++/7/bits/stl_list.h:1152:7: note:   in call to ‘void std::__cxx11::list<_Tp, _Alloc>::pop_back() [with _Tp = double; _Alloc = std::allocator<double>]’
       pop_back() _GLIBCXX_NOEXCEPT
       ^~~~~~~~
src/mean.cc:33:29: error: passing ‘const csce240::Mean’ as ‘this’ argument discards qualifiers [-fpermissive]
   push_front(tempList.back());
                             ^
In file included from /usr/include/c++/7/list:63:0,
                 from inc/mean.h:9,
                 from src/mean.cc:2:
/usr/include/c++/7/bits/stl_list.h:1067:7: note:   in call to ‘void std::__cxx11::list<_Tp, _Alloc>::push_front(const value_type&) [with _Tp = double; _Alloc = std::allocator<double>; std::__cxx11::list<_Tp, _Alloc>::value_type = double]’
       push_front(const value_type& __x)
       ^~~~~~~~~~

The closest solution I could find was to add const to the end of the function definition, however that was already in the definition to start with. Here is are the .h and .cc files:

https://pastebin.com/rw8hTHvH

Aucun commentaire:

Enregistrer un commentaire