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. Is this a Bug or What?

Is this a Bug or What?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studiohelpquestion
17 Posts 9 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.
  • S sanket patel

    Actually !! I was asked to find the ways to access private members outside the class? so one method is using friends.... and i thought of this as the other way... Thanks,

    sanket

    T Offline
    T Offline
    toxcct
    wrote on last edited by
    #8

    sanket.patel wrote:

    I was asked to find the ways to access private members outside the class

    and you chose the worst... if members are private, it's to deliberately hide them from the outside. look. if you have an object engine, do you know how it works internally ? certainly not. you only see the apis (accelerator, starter, etc...). anyway, have you thought to members accessors (getters, setters) ?


    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

    S 1 Reply Last reply
    0
    • T toxcct

      sanket.patel wrote:

      I was asked to find the ways to access private members outside the class

      and you chose the worst... if members are private, it's to deliberately hide them from the outside. look. if you have an object engine, do you know how it works internally ? certainly not. you only see the apis (accelerator, starter, etc...). anyway, have you thought to members accessors (getters, setters) ?


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      S Offline
      S Offline
      sanket patel
      wrote on last edited by
      #9

      Thank you very much! yeah I know about getters and setters and I know I choose the worst! but the the question is about that only.. i.e. the unusual ways to access the private data. Thanks,

      sanket

      1 Reply Last reply
      0
      • S sanket patel

        Thanks!! but dont you think this should not be allowed??

        sanket

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #10

        VB and C# are languages written to cater to the lowest common denominator. C++ assumes a level of skill in the developer. #define is a hangover from C, which C++ is derived from. The designer of C++ would prefer it was not there, but it's still true that his design philosophy is to give the language powerful features and assume his users know how to use them.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        B R 2 Replies Last reply
        0
        • S sanket patel

          Hello All !! I am using visual studio 6.0 I tried to access the private class member outside the class using #define macro. here is the code. I was able to access private member outside the class? why did this work? This should be allowed or not?

          #define private public
          
          class A
          {
          
          private:
          	int i;
          
          public:
          	A()
          	{
          		i = 44;
          	}
          
          };
          
          int main()
          {
          	A obA;
          	cout<<"\ni = "<
          

          sanket

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #11

          GIGO - if you pull stunts like that, don't be surprised when you get odd results.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

          1 Reply Last reply
          0
          • S sanket patel

            Hello All !! I am using visual studio 6.0 I tried to access the private class member outside the class using #define macro. here is the code. I was able to access private member outside the class? why did this work? This should be allowed or not?

            #define private public
            
            class A
            {
            
            private:
            	int i;
            
            public:
            	A()
            	{
            		i = 44;
            	}
            
            };
            
            int main()
            {
            	A obA;
            	cout<<"\ni = "<
            

            sanket

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #12

            sanket.patel wrote:

            #define private public

            My opinion is that you will *EXCEL* in the "Coding Horros" forum. Well, what are you waiting for? Post some of your fantastic code there! :|


            Nobody can give you wiser advice than yourself. - Cicero ப்ரம்மா

            1 Reply Last reply
            0
            • S sanket patel

              Hello All !! I am using visual studio 6.0 I tried to access the private class member outside the class using #define macro. here is the code. I was able to access private member outside the class? why did this work? This should be allowed or not?

              #define private public
              
              class A
              {
              
              private:
              	int i;
              
              public:
              	A()
              	{
              		i = 44;
              	}
              
              };
              
              int main()
              {
              	A obA;
              	cout<<"\ni = "<
              

              sanket

              C Offline
              C Offline
              cp9876
              wrote on last edited by
              #13

              To make the most of your coding experience, you probably should try: To save testing: #define true false this always happens anyway: #define this NULL to avoid accidental deletion #define delete /##/ avoid wasting loop iterations: #define break continue just in case the others are boring: #define try do #define catch while

              Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

              M 1 Reply Last reply
              0
              • C Christian Graus

                VB and C# are languages written to cater to the lowest common denominator. C++ assumes a level of skill in the developer. #define is a hangover from C, which C++ is derived from. The designer of C++ would prefer it was not there, but it's still true that his design philosophy is to give the language powerful features and assume his users know how to use them.

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                B Offline
                B Offline
                BadKarma
                wrote on last edited by
                #14

                Christian Graus wrote:

                #define is a hangover from C, which C++ is derived from. The designer of C++ would prefer it was not there, but it's still true that his design philosophy is to give the language powerful features and assume his users know how to use them.

                A hangover, maybe, but it is o so powerful. But with every powerful it should be used with care. #define is a dangerous tool in the hands of the unexperienced.:-D

                codito ergo sum

                C 1 Reply Last reply
                0
                • C Christian Graus

                  VB and C# are languages written to cater to the lowest common denominator. C++ assumes a level of skill in the developer. #define is a hangover from C, which C++ is derived from. The designer of C++ would prefer it was not there, but it's still true that his design philosophy is to give the language powerful features and assume his users know how to use them.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #15

                  You got sig-ed. 'nce again. :-D


                  VB and C# are languages written to cater to the lowest common denominator. C++ assumes a level of skill in the developer. - Christian Graus

                  1 Reply Last reply
                  0
                  • B BadKarma

                    Christian Graus wrote:

                    #define is a hangover from C, which C++ is derived from. The designer of C++ would prefer it was not there, but it's still true that his design philosophy is to give the language powerful features and assume his users know how to use them.

                    A hangover, maybe, but it is o so powerful. But with every powerful it should be used with care. #define is a dangerous tool in the hands of the unexperienced.:-D

                    codito ergo sum

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #16

                    BadKarma wrote:

                    hangover, maybe, but it is o so powerful.

                    I agree with Stroustrup. I try to avoid using it whever I can, I think it's a poor tool. But, it is powerful, and no doubt can be used effectively at times.

                    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                    1 Reply Last reply
                    0
                    • C cp9876

                      To make the most of your coding experience, you probably should try: To save testing: #define true false this always happens anyway: #define this NULL to avoid accidental deletion #define delete /##/ avoid wasting loop iterations: #define break continue just in case the others are boring: #define try do #define catch while

                      Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #17

                      EXCELLENT! These fixed a bunch of my problems. Thanks!

                      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                      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