[openbeos-midi] Re: (no subject)

  • From: "Matthijs Hollemans" <matthijs@xxxxxxxxxxxxxxxxxxx>
  • To: <openbeos-midi@xxxxxxxxxxxxx>
  • Date: Wed, 23 Oct 2002 10:35:49 +0100

> I will write BMidiEndPoint and all derived class
> but I have some questions

You are very brave ;-)

> - And what is the Key Word "mutable" before BLocker

I can't really help you with the other questions (yet), but this one
I can answer. You may have noticed that IsConnected() and
Connections() are "const" member functions, which means that these
functions promise not to change the object. But what if these
functions need to lock the object? That would modify the BLocker,
and we just promised we would not change the object.

The solution is to make the BLocker "mutable", which means that it
may be changed by the IsConnected() and Connections() functions.
(You can achieve the same with a cast, but that is ugly.) The
BLocker may now be changed even if the BMidiLocalProducer is a
"const" object.

To clarify: when an object is "const" it means that the
"client-visible state" is not going to change. Since the BLocker is
just part of the implementation, it is not visible by the client.
That is what the mutable keyword does: it tells the compiler that a
certain variable is not part of the client-visible state. (The
client in this case is of course the code that uses the
BMidiLocalProducer object.)

For more information see:
<http://www.parashift.com/c++-faq-lite/const-correctness.html> and

I hope that makes it a little clearer,


Other related posts: