Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. what do functions like this behave like

what do functions like this behave like

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rahulmballal
    wrote on last edited by
    #1

    object* Function()const; when are they called? whats their use? please explain the syntax someone rahul

    P L R 3 Replies Last reply
    0
    • R rahulmballal

      object* Function()const; when are they called? whats their use? please explain the syntax someone rahul

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      http://www.possibility.com/Cpp/const.html[^]


      -prakash

      1 Reply Last reply
      0
      • R rahulmballal

        object* Function()const; when are they called? whats their use? please explain the syntax someone rahul

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Consider we have a class CFoo

        CFoo
        {
        protected :
        //...//
        ** char* m_sText;**
        //...//
        public :
        //...//
        ** char* getText() const;**
        //...//

        }

        char* CFoo::getText() const
        {
        return m_sText;
        }

        By writing const keyword we make sure that CFoo::getText function does not modify the object for which it is called.So we can't write inside , for example :

        char* CFoo::getText() const
        {
        m_sText="Hello"; //error
        return m_sText;
        }


        "Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill

        1 Reply Last reply
        0
        • R rahulmballal

          object* Function()const; when are they called? whats their use? please explain the syntax someone rahul

          R Offline
          R Offline
          Renjith Ramachandran
          wrote on last edited by
          #4

          its a constant function, that can't modify variables with in that function, the compiler will raise an error on that situation. Ninety-eight percent of the thrill comes from knowing that the thing you designed works, and works almost the way you expected it would. If that happens, part of you is in that machine.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups