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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. protected, public and private

protected, public and private

Scheduled Pinned Locked Moved C / C++ / MFC
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.
  • K Offline
    K Offline
    karmendra_js
    wrote on last edited by
    #1

    I just got a lil confussed here. I want to access a variable using the object of the class. classXYZ objectname= new classXYZ(); objectname.variablename=100; so which access specifier is best for variablename. Thanks.

    S G T 3 Replies Last reply
    0
    • K karmendra_js

      I just got a lil confussed here. I want to access a variable using the object of the class. classXYZ objectname= new classXYZ(); objectname.variablename=100; so which access specifier is best for variablename. Thanks.

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      If that code is outside classXYZ, you have no choice, it must be declared public. Regards Senthil Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      1 Reply Last reply
      0
      • K karmendra_js

        I just got a lil confussed here. I want to access a variable using the object of the class. classXYZ objectname= new classXYZ(); objectname.variablename=100; so which access specifier is best for variablename. Thanks.

        G Offline
        G Offline
        Gary R Wheeler
        wrote on last edited by
        #3

        public: Accessible outside the class. protected: Accessible to instances of the class, and to any classes derived from it. private: Accessible only by the class itself.


        Software Zen: delete this;

        1 Reply Last reply
        0
        • K karmendra_js

          I just got a lil confussed here. I want to access a variable using the object of the class. classXYZ objectname= new classXYZ(); objectname.variablename=100; so which access specifier is best for variablename. Thanks.

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          karmendra_js wrote:

          I want to access a variable using the object of the class.

          Accessing Class Variable outside class is not part of Good design.. always create Get and put function to access variable outside the class.

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          cheers, Alok Gupta VC Forum Q&A :- I/ IV

          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