Topic: mutable - please help


Author: jarausch@numa1.igpm.rwth-aachen.de (Helmut Jarausch)
Date: 1998/01/15
Raw View
Hi,
please help me to understand the following error messages concerning
'mutable'  unless both compilers are buggy at that.

In my class 'Mat_Vec' I have

mutable MatVecMMC* MMC;   //  MMC is my memory control block

and in class 'MatVecMMC'  I want to declare

static mutable MatVecMMC* get( MMC_Size Size );  // get is my allocator

where I meant 'get' to return a pointer to a 'mutable' object
of class MatVecMMC

Unfortunately

egcs version 1.0.1  says
IGPMatrix.h:229: static `get' cannot be declared `mutable'

whereas
SGI CC 7.2  says

"IGPMatrix.h", line 229: error(1081): more than one storage class may not be
          specified
    static mutable MatVecMMC* get( MMC_Size Size );


Or am I wrong in that I should have said  (mutable MatVecMMC)*  ???

Thanks so much for your help,

Helmut.

--
Helmut Jarausch
Lehrstuhl f. Numerische Mathematik
Institute of Technology, RWTH Aachen
D 52056 Aachen, Germany
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1998/01/16
Raw View
Helmut Jarausch wrote:
>
> Hi,
> please help me to understand the following error messages concerning
> 'mutable'  unless both compilers are buggy at that.
>
> In my class 'Mat_Vec' I have
>
> mutable MatVecMMC* MMC;   //  MMC is my memory control block
>
> and in class 'MatVecMMC'  I want to declare
>
> static mutable MatVecMMC* get( MMC_Size Size );  // get is my allocator
>
> where I meant 'get' to return a pointer to a 'mutable' object
> of class MatVecMMC
>
> Unfortunately
>
> egcs version 1.0.1  says
> IGPMatrix.h:229: static `get' cannot be declared `mutable'
>
> whereas
> SGI CC 7.2  says
>
> "IGPMatrix.h", line 229: error(1081): more than one storage class may not be
>           specified
>     static mutable MatVecMMC* get( MMC_Size Size );
>
> Or am I wrong in that I should have said  (mutable MatVecMMC)*  ???
>
> Thanks so much for your help,

Different to object members, the return value is not automatically
made const for const objects, therefore mutable makes no sense there.
So just drop this mutable (while keeping it on the member, of course),
and your code will work as expected.


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: comeau@panix.com (Greg Comeau)
Date: 1998/01/17
Raw View
In article <69kk1k$dkp$1@nets3.rz.RWTH-Aachen.DE> jarausch@numa1.igpm.rwth-aachen.de (Helmut Jarausch) writes:
>please help me to understand the following error messages concerning
>'mutable'  unless both compilers are buggy at that.
>
>In my class 'Mat_Vec' I have
>
>mutable MatVecMMC* MMC;   //  MMC is my memory control block
>
>and in class 'MatVecMMC'  I want to declare
>
>static mutable MatVecMMC* get( MMC_Size Size );  // get is my allocator
>
>where I meant 'get' to return a pointer to a 'mutable' object
>of class MatVecMMC

There are two problems here:
(1) static and mutable are both storage-class-specifiers,
and you cannot specify more than one of them.

This makes sense in this case because static means that it
won't be part of the object space, hence mutable is inapplicable.

(2) mutable is for objects, not for functions.
Your get() is a function, hence it in inapplicable additionally.

In short, mutable can only apply to non-static, non-const,
non-reference data members of a class.

You feel that you need it, so the question is: Why?
What are you doing that you feel requires it?

If get() is going to return MMC, which is mutable, and hence, by definition.
cannot be const, then just return it.  You don't need it for the
function return type.  The "only" reason that you need it for the
member is that they are subobjects and it is too lexically disjoint
for the compiler to know if/when its containing object's declaration is
const and when it is not.  Leaving off const (immutable) from the
return value means that it is by default mutable.

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
               Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
 Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]