Thread: warning C4141: 'mutable' : used more than once

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    519

    warning C4141: 'mutable' : used more than once

    Hi,

    I'm trying to use const correctness as far as possible. To allow member functions which just lock/unlock a mutex and else doing nothing but reading out some information to be const, I usually declare the mutex class members mutable, which works well so far.
    Now I had a class with more than one mutex (all decleared mutable) and msvc gives me the warning shown in the topic.

    Is there anything to care about for me?

    Thank you!

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Post the exact code that produces the warning. The description claims it happens when you do
    Code:
    mutable mutable mutex m_mutex;
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Thank you, this was exactly the problem.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by pheres View Post
    Thank you, this was exactly the problem.
    So wait. The error said "mutable used more than once." And on the line in question, the keyword "mutable" was in fact, used more than once. And this confounded you?

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Perhaps it came to pass like this?
    Code:
    #define mint mutable int
    
    class A
    {
        mutable mint b;
    };
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by anon View Post
    Perhaps it came to pass like this?
    Code:
    #define mint mutable int
    
    class A
    {
        mutable mint b;
    };
    That seems more plausible.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Quote Originally Posted by brewbuck View Post
    So wait. The error said "mutable used more than once." And on the line in question, the keyword "mutable" was in fact, used more than once. And this confounded you?

    Hehe, yes that was it
    The warning showed up in the compile cycle in which I also added another mutable member (and probably messed up the first one with some copy&paste magic). So I mentally charged the new mutable member and didn't try to look on other possible causes. Damn brain.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM