const objects ->const member functions?

Discussion in 'C++' started by puzzlecracker, Feb 7, 2005.

  1. I am just curious: if you declare an object constant - can it call NOT
    constant member functions of the class or only constant ones?


    are there generic rules for such objects?


    THANKs
     
    puzzlecracker, Feb 7, 2005
    #1
    1. Advertising

  2. puzzlecracker

    Noah Roberts Guest

    puzzlecracker wrote:
    > I am just curious: if you declare an object constant - can it call NOT
    > constant member functions of the class or only constant ones?


    I believe only const member functions may be called on a const object.
    >
    >
    > are there generic rules for such objects?


    const objects are meant to be non-changing. A function that will not
    alter the instance it is operating on should be labeled as const to
    represent this fact. Member functions that do change the internals of
    their instances must not be used on an object that is not supposed to
    change.

    It is pretty straight forward if you keep in mind what 'const' means.
    It means 'constant'.

    Hope that helps.
     
    Noah Roberts, Feb 7, 2005
    #2
    1. Advertising

  3. puzzlecracker

    Siemel Naran Guest

    "puzzlecracker" <> wrote in message

    > I am just curious: if you declare an object constant - can it call NOT
    > constant member functions of the class or only constant ones?


    It can only call constant ones.

    > are there generic rules for such objects?


    What do you mean?
     
    Siemel Naran, Feb 7, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cheeser
    Replies:
    17
    Views:
    739
    cpp_weenie
    Oct 18, 2003
  2. Javier
    Replies:
    2
    Views:
    585
    James Kanze
    Sep 4, 2007
  3. fungus
    Replies:
    13
    Views:
    902
    fungus
    Oct 31, 2008
  4. Hicham Mouline
    Replies:
    0
    Views:
    441
    Hicham Mouline
    Apr 23, 2009
  5. Hicham Mouline
    Replies:
    1
    Views:
    423
    Michael DOUBEZ
    Apr 24, 2009
Loading...

Share This Page