Thread: const and non const

  1. #1
    Unregistered
    Guest

    const and non const

    I now that a non const member function on a non const object. And const member function on a const object. But can a const object parameter use member function that is not const?....

    Tyree

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    What are you talking about? There aren't any restrictions for const-types except that they cannot be changed.
    // Gliptic

  3. #3
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You can pass a non-const object to a function taking const argument, it just won't be modified. You, however, cannot pass a const object to a non-const function.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    164

    Thumbs down

    ...if you don't cast it.
    // Gliptic

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    And if you ever cast a const to a non-const your will go directly to programmers hell !

    >But can a const object parameter use member function that is not const?....

    No. Thats the reason behind it all. A const anything isn't changeable. So non-const member functions ( those functions changing the inner state of the object ) cannot be called.


    *wavesPitchFork* Never cast a const to non-const.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed