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. In C++ compiler providing the default copy constructor ,then why do we need copy constructor

In C++ compiler providing the default copy constructor ,then why do we need copy constructor

Scheduled Pinned Locked Moved C / C++ / MFC
c++
9 Posts 5 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
    ranjithsubra
    wrote on last edited by
    #1

    Hello, Could you please provide some examples "

    In C++ compiler providing the default copy constructor ,then why do we need copy constructor

    . " Thanks and Regards, Ranjithkumar.S

    ranjith

    L J S 3 Replies Last reply
    0
    • R ranjithsubra

      Hello, Could you please provide some examples "

      In C++ compiler providing the default copy constructor ,then why do we need copy constructor

      . " Thanks and Regards, Ranjithkumar.S

      ranjith

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

      When you want something other than the default behavior.

      R 1 Reply Last reply
      0
      • L Lost User

        When you want something other than the default behavior.

        R Offline
        R Offline
        ranjithsubra
        wrote on last edited by
        #3

        provide some example

        ranjith

        L D 3 Replies Last reply
        0
        • R ranjithsubra

          provide some example

          ranjith

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

          If this was a write code to order service, what sort of an example would I write for you? But since this is not a coding service, no, I won't do your homework for you.

          R 1 Reply Last reply
          0
          • L Lost User

            If this was a write code to order service, what sort of an example would I write for you? But since this is not a coding service, no, I won't do your homework for you.

            R Offline
            R Offline
            ranjithsubra
            wrote on last edited by
            #5

            thank you

            ranjith

            1 Reply Last reply
            0
            • R ranjithsubra

              provide some example

              ranjith

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Copy constructors - cppreference.com[^] Default Copy Constructor - C++ Forum[^]

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              1 Reply Last reply
              0
              • R ranjithsubra

                Hello, Could you please provide some examples "

                In C++ compiler providing the default copy constructor ,then why do we need copy constructor

                . " Thanks and Regards, Ranjithkumar.S

                ranjith

                J Offline
                J Offline
                jeron1
                wrote on last edited by
                #7

                There are tons of examples out there, here is but one[^].

                "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                1 Reply Last reply
                0
                • R ranjithsubra

                  provide some example

                  ranjith

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

                  Basically when you need custom logic in copying. For example, dynamic memory allocation in pointer members. Same thing is applicable in assignment operator overloading too.

                  1 Reply Last reply
                  0
                  • R ranjithsubra

                    Hello, Could you please provide some examples "

                    In C++ compiler providing the default copy constructor ,then why do we need copy constructor

                    . " Thanks and Regards, Ranjithkumar.S

                    ranjith

                    S Offline
                    S Offline
                    Saravanan Sundaresan
                    wrote on last edited by
                    #9

                    May be it is orthogonal information, If we want to hide/restrict usage of default copy constructor, we need to provide override declaration in private section of class, and no definition for that. This ensures preventing usages of copy constructor

                    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