Thread: Why function that is declared can't call others function aren't declared const?

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    52

    Why function that is declared can't call others function aren't declared const?

    or opostition.....only functions that are declared in "class" or any functions?
    I don't understand why ??Anybody can tell me deeply about structures of them...thanks very much....

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Can you please rephrase that? I am having trouble understanding what you've said.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    If this is what you mean, you can't call a non const function from within a const function. It is an error to do so. A const member guarantees that the object of which it was called cannot be altered. If you were allowed to call a function that altered the object from within a function that didn't allow you to alter that object, you would have a case of one broken rule.

    When you create a const member function you are also changing the implicit this parameter to a pointer to const when that function is called. This ensure that you are flagged with a compile-time error on most situations where you try to alter the object through a const member function. Either by directly manipulating data members or by calling non const functions.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    52
    thanks very much for your answer.. Mario F

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM