Static and mutable data type.

Hi,

I was wondering, can a class attribute be static and mutable?

For example,

1
2
3
4
5
6
typedef tbb::queing_mutex MutexType;

class MyClass {
  private:
    static mutable MutexType mutex;
};


I admit it's a weird question, but I've been a while wondering about it.
Thanks.
Last edited on
I think the situation makes no sense. I cannot wrap my mind around a scenario that would require this: The mutable keyword allows the variable to change even in the case of of a const object. But the variable is not part of any object because it is also being marked as static. Making it static also means that you cannot obtain a const reference, right? Nor will the variable be contained in a const object.

So I cannot think of a case use for this. Anyone else? OP: Do you have a scenario for this?
Thanks for your reply, webJose.

A scenario? Well, not really. I was thinking of something like having two threads that insert numbers in a global vector using the static mutex. And the mutable thing, for a method like WriteDataToFile() const , in which the data is not modified, yet a mutex is required to ensure that only one thread is writing to the file at a time.

But as I said in the other post, I was just wondering. Too much free time :)
I think static members are already mutable, so you don't use the keyword.
Thanks Galik!
Topic archived. No new replies allowed.