I’m trying to compile something like this:
#include <list>
class thread
{
public:
static volatile std::list<thread *> threadList; //This is also protected by a mutex
};
volatile std::list<thread *> thread::threadList;
void main()
{
thread A;
thread::threadList.push_back(&A);
thread::threadList.remove(&A);
}
I get these errors when trying to compile:
test.cpp(14): error C2663: 'std::list::push_back' : 2 overloads have no legal conversion for 'this' pointer
with
[
_Ty=thread *
]
test.cpp(15): error C2662: 'std::list::remove' : cannot convert 'this' pointer from 'volatile std::list' to 'std::list &'
with
[
_Ty=thread *
]
Conversion loses qualifiers
What am I doing wrong?
EDIT: fixed some formatting errors with < and >
EDIT2: threadList is protected by a mutex, I just didn’t put it here for simplicity
Remove volatile and remove the problem. So for the real answer, it might help if you explain why you need to volatile, and what it is intended to mean here. It won’t make the whole list be treated as volatile.
See also previous answer