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. c?C++

c?C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
15 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.
  • CPalliniC CPallini

    Nice subject. :rolleyes: BTW, Generally speaking, I don't see problems. Be aware, anyway, that = operator is called...

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    E Offline
    E Offline
    Eytukan
    wrote on last edited by
    #4

    lol :) I'm looking at the line in all possible views :~ but not able to guess anything wrong. Funny :) looks like an object spitting on the air facing up.

    He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

    P 1 Reply Last reply
    0
    • E Eytukan

      lol :) I'm looking at the line in all possible views :~ but not able to guess anything wrong. Funny :) looks like an object spitting on the air facing up.

      He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

      P Offline
      P Offline
      Pankaj D Dubey
      wrote on last edited by
      #5

      well, Vunic, If you don't worry about self assignment, you'll expose yourself to some very subtle bugs that have very subtle and often disastrous symptoms. :)

      E 1 Reply Last reply
      0
      • P Pankaj D Dubey

        well, Vunic, If you don't worry about self assignment, you'll expose yourself to some very subtle bugs that have very subtle and often disastrous symptoms. :)

        E Offline
        E Offline
        Eytukan
        wrote on last edited by
        #6

        dubeypankaj wrote:

        you'll expose yourself to some very subtle bugs that have very subtle and often disastrous symptoms

        For example..

        He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

        CPalliniC 1 Reply Last reply
        0
        • E Eytukan

          dubeypankaj wrote:

          you'll expose yourself to some very subtle bugs that have very subtle and often disastrous symptoms

          For example..

          He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #7

          VuNic wrote:

          For example..

          If you do weird things in the = operator (re-)definition, for instance, i.e. if you write it (implicitely) assuming it will be never used to do self-assignment. Have a look at the following code (please note, it is silly, written just to spot the point; moreover no check is done on memory allocation, for brevity)

          class Foo
          {
          static const int N = 10;
          char * _buf;
          public:
          Foo(char c){_buf = new char [N]; memset(_buf, c, N);}
          Foo & operator=(const Foo & foo)
          {
          if ( _buf )
          {
          delete _buf;
          _buf = new char[N];
          }
          memcpy(_buf, foo._buf, N);
          return *this;
          }
          Foo(const Foo & foo){...}
          };

          void main()
          {
          Foo f('A');
          f = f;
          }

          :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          L 1 Reply Last reply
          0
          • CPalliniC CPallini

            VuNic wrote:

            For example..

            If you do weird things in the = operator (re-)definition, for instance, i.e. if you write it (implicitely) assuming it will be never used to do self-assignment. Have a look at the following code (please note, it is silly, written just to spot the point; moreover no check is done on memory allocation, for brevity)

            class Foo
            {
            static const int N = 10;
            char * _buf;
            public:
            Foo(char c){_buf = new char [N]; memset(_buf, c, N);}
            Foo & operator=(const Foo & foo)
            {
            if ( _buf )
            {
            delete _buf;
            _buf = new char[N];
            }
            memcpy(_buf, foo._buf, N);
            return *this;
            }
            Foo(const Foo & foo){...}
            };

            void main()
            {
            Foo f('A');
            f = f;
            }

            :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #8

            CPallini wrote:

            i.e. if you write it (implicitely) assuming it will be never used to do self-assignment.

            And why would someone do that? Isn't that considered Best Practice? Or is this question about something entirely different than what I have been able to interpret? It seems to me that it is about this subject[^]

            CPalliniC 1 Reply Last reply
            0
            • P Pankaj D Dubey

              What are the problems associated with self assignment(object = object; )?

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #9

              dubeypankaj wrote:

              What are the problems associated with self assignment

              The answer is, whatever problems were introduced in the class being used in the self assignment. Keep studying. :beer:

              1 Reply Last reply
              0
              • L led mike

                CPallini wrote:

                i.e. if you write it (implicitely) assuming it will be never used to do self-assignment.

                And why would someone do that? Isn't that considered Best Practice? Or is this question about something entirely different than what I have been able to interpret? It seems to me that it is about this subject[^]

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #10

                led mike wrote:

                And why would someone do that?

                Exactly that? Just CPallini... :rolleyes:

                led mike wrote:

                Isn't that considered Best Practice?

                Nope, anyway it's a good candidate to be inserted into the WPF (Worst Practice Foundation). :-D

                led mike wrote:

                Or is this question about something entirely different than what I have been able to interpret?

                led mike wrote:

                And why would someone do that? Isn't that considered Best Practice? Or is this question about something entirely different than what I have been able to interpret? It seems to me that it is about this subject[^]

                Nope, you understand it correctly and, damn... If you recalled that page before my post I hadn't to put the weird code therein. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                In testa che avete, signor di Ceprano?

                L P 2 Replies Last reply
                0
                • CPalliniC CPallini

                  led mike wrote:

                  And why would someone do that?

                  Exactly that? Just CPallini... :rolleyes:

                  led mike wrote:

                  Isn't that considered Best Practice?

                  Nope, anyway it's a good candidate to be inserted into the WPF (Worst Practice Foundation). :-D

                  led mike wrote:

                  Or is this question about something entirely different than what I have been able to interpret?

                  led mike wrote:

                  And why would someone do that? Isn't that considered Best Practice? Or is this question about something entirely different than what I have been able to interpret? It seems to me that it is about this subject[^]

                  Nope, you understand it correctly and, damn... If you recalled that page before my post I hadn't to put the weird code therein. :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #11

                  CPallini wrote:

                  Nope, anyway it's a good candidate to be inserted into the WPF (Worst Practice Foundation).

                  :confused: It's not considered best practice to implement an assignment operator the way it is shown in the parashift FAQ Lite to exclude self assignment?

                  CPalliniC 1 Reply Last reply
                  0
                  • L led mike

                    CPallini wrote:

                    Nope, anyway it's a good candidate to be inserted into the WPF (Worst Practice Foundation).

                    :confused: It's not considered best practice to implement an assignment operator the way it is shown in the parashift FAQ Lite to exclude self assignment?

                    CPalliniC Offline
                    CPalliniC Offline
                    CPallini
                    wrote on last edited by
                    #12

                    Nope. I was talking about my code sample (supposing your sentence ironical). Sorry for the misunderstanding. :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    In testa che avete, signor di Ceprano?

                    L 1 Reply Last reply
                    0
                    • CPalliniC CPallini

                      Nope. I was talking about my code sample (supposing your sentence ironical). Sorry for the misunderstanding. :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      L Offline
                      L Offline
                      led mike
                      wrote on last edited by
                      #13

                      CPallini wrote:

                      Sorry for the misunderstanding.

                      LMAO Some times texting is a a BEE-ATCH! :laugh: Using the IPhone would have solved all this :-D

                      1 Reply Last reply
                      0
                      • CPalliniC CPallini

                        led mike wrote:

                        And why would someone do that?

                        Exactly that? Just CPallini... :rolleyes:

                        led mike wrote:

                        Isn't that considered Best Practice?

                        Nope, anyway it's a good candidate to be inserted into the WPF (Worst Practice Foundation). :-D

                        led mike wrote:

                        Or is this question about something entirely different than what I have been able to interpret?

                        led mike wrote:

                        And why would someone do that? Isn't that considered Best Practice? Or is this question about something entirely different than what I have been able to interpret? It seems to me that it is about this subject[^]

                        Nope, you understand it correctly and, damn... If you recalled that page before my post I hadn't to put the weird code therein. :)

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        P Offline
                        P Offline
                        Pankaj D Dubey
                        wrote on last edited by
                        #14

                        Thanx for the adjective used for me(Worst Practice Foundation user). Any way, my question was what are the problems associated with self assignment of an object to itself? Ppl gave me all the comments and on my programming as well rather to answer my question, but yes, i got the answer, please refer the following link: http://faqs.cs.uu.nl/na-dir/C++-faq/part06.html Refer: SECTION [12]: Assignment operators(in the link above) Thanx & Regards

                        CPalliniC 1 Reply Last reply
                        0
                        • P Pankaj D Dubey

                          Thanx for the adjective used for me(Worst Practice Foundation user). Any way, my question was what are the problems associated with self assignment of an object to itself? Ppl gave me all the comments and on my programming as well rather to answer my question, but yes, i got the answer, please refer the following link: http://faqs.cs.uu.nl/na-dir/C++-faq/part06.html Refer: SECTION [12]: Assignment operators(in the link above) Thanx & Regards

                          CPalliniC Offline
                          CPalliniC Offline
                          CPallini
                          wrote on last edited by
                          #15

                          dubeypankaj wrote:

                          Thanx for the adjective used for me(Worst Practice Foundation user).

                          It wasn't used for you, it was for my sample code (see [^])... In a bad mood today? :-D I just wanted to make Vunic aware that, yes, there might be problems with self-assignment. Of course the link provided by led mike spots the point far better than I did. :)

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                          [My articles]

                          In testa che avete, signor di Ceprano?

                          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