In the subclass, I have a private field std::mutex m
that I use in implementing the pure virtual method of the base class to return the value in a thread-safe way (the value can be updated by another thread):
int SubClass::get() const
{
std::lock_guard<std::mutex> lck(m);
return value;
}
The compiler tells me that this violates the correctness of const, creating an error:
error: binding 'const std :: mutex' to a link like 'Stand :: lock_guard :: mutex_type & {aka std :: mutex &}' discards classifiers
Is there a way to make this compatible and use it std::lock_guard
with const-correct? A simple change const std::lock_guard
does not change anything. I really don’t understand which part is problematic, then again I am completely new to C ++ ...