How to write a paragraph explain the Big 3?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmrcm
    New Member
    • May 2007
    • 6

    How to write a paragraph explain the Big 3?

    Hi all, I am new here. I wonder anybody knows how to write a paragraph explaining the “ Big 3” - destructor, copy constructor and assignment operator?
    Thanks in advance!
  • AdrianH
    Recognized Expert Top Contributor
    • Feb 2007
    • 1251

    #2
    Originally posted by cmrcm
    Hi all, I am new here. I wonder anybody knows how to write a paragraph explaining the “ Big 3” - destructor, copy constructor and assignment operator?
    Thanks in advance!
    I'm sure that there are many here who can write a paragraph about the 'Big 3', but that is not what we do here. We help our members learn, not give them the answers.

    If you write a paragraph about the 'Big 3', we can look at it and direct you accordingly.

    Looking forward to hearing your paragraph.


    Adrian

    Comment

    • cmrcm
      New Member
      • May 2007
      • 6

      #3
      I am not native English speaker. In my case, it is not easy to describe the big 3 well in English.
      My answer is:
      Copy constructor: when creating an object, the compiler calls the constructor automatically.
      Destructor: automatically called by the compiler when an object archieve itsclosure.
      Assignment operator: copy the right hand side into the left hand side.

      I know my answer is not complete, any body can help me?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by cmrcm
        I am not native English speaker. In my case, it is not easy to describe the big 3 well in English.
        My answer is:
        Copy constructor: when creating an object, the compiler calls the constructor automatically.
        Destructor: automatically called by the compiler when an object archieve itsclosure.
        Assignment operator: copy the right hand side into the left hand side.

        I know my answer is not complete, any body can help me?
        Here are a few hints:
        Code:
        {
           YourClass a; // default constructor;
           ...
           YourClass b= a; // copy constructor
           ...
           yourCallByValueFunction(a); // copy constructor;
           ...
           a= b; // operator=
        } // destructor
        kind regards,

        Jos

        Comment

        • cmrcm
          New Member
          • May 2007
          • 6

          #5
          Originally posted by JosAH
          Here are a few hints:
          Code:
          {
             YourClass a; // default constructor;
             ...
             YourClass b= a; // copy constructor
             ...
             yourCallByValueFunction(a); // copy constructor;
             ...
             a= b; // operator=
          } // destructor
          kind regards,

          Jos
          Thanks for reply. I think I am clear about the constructor and operator, could you explain more about the destructor please?

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by cmrcm
            Thanks for reply. I think I am clear about the constructor and operator, could you explain more about the destructor please?
            Well, a destructor destructs an object. When the object held resources the
            destructor is the place to relinguish those resources (dynamic memory, files,
            sockets, screen estate etc. etc.)

            kind regards,

            Jos

            ps. can you show us the paragraph you had to write on the "big three"?

            Comment

            • cmrcm
              New Member
              • May 2007
              • 6

              #7
              Originally posted by JosAH
              ps. can you show us the paragraph you had to write on the "big three"?
              Thanks for explaining. What do you mean by the "paragraph I had"? The question or my answer?

              Comment

              • AdrianH
                Recognized Expert Top Contributor
                • Feb 2007
                • 1251

                #8
                Originally posted by JosAH
                Here are a few hints:
                Code:
                {
                   YourClass a; // default constructor;
                   ...
                   YourClass b= a; // copy constructor
                   ...
                   yourCallByValueFunction(a); // copy constructor;
                   ...
                   a= b; // operator=
                } // destructor
                kind regards,

                Jos
                You also forgot
                Code:
                   YourClass b= a; // copy constructor
                Adrian

                Comment

                • AdrianH
                  Recognized Expert Top Contributor
                  • Feb 2007
                  • 1251

                  #9
                  Originally posted by cmrcm
                  Thanks for explaining. What do you mean by the "paragraph I had"? The question or my answer?
                  Sounds like you have it under control.

                  Good luck,


                  Adrian

                  Comment

                  • cmrcm
                    New Member
                    • May 2007
                    • 6

                    #10
                    Originally posted by JosAH
                    Here are a few hints:
                    Code:
                    {
                       YourClass a; // default constructor;
                       ...
                       YourClass b= a; // copy constructor
                       ...
                       yourCallByValueFunction(a); // copy constructor;
                       ...
                       a= b; // operator=
                    } // destructor
                    kind regards,

                    Jos
                    One more thing, are the a and b in 'YourClass a', 'YourClass b= a', 'yourCallByValu eFunction(a)' and 'a= b' the same? what's the relationship between them?

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by cmrcm
                      One more thing, are the a and b in 'YourClass a', 'YourClass b= a', 'yourCallByValu eFunction(a)' and 'a= b' the same? what's the relationship between them?
                      'a' and 'b' are two different objects but both instantiations from the same class.

                      kind regards,

                      Jos

                      Comment

                      Working...