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. copy constructor

copy constructor

Scheduled Pinned Locked Moved C / C++ / MFC
8 Posts 6 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 Offline
    S Offline
    Scorpio
    wrote on last edited by
    #1

    can I prevent any copy constructor being called for my class.

    C K 2 Replies Last reply
    0
    • S Scorpio

      can I prevent any copy constructor being called for my class.

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Yes, just make it private (or protected).


      Cédric Moonen Software developer
      Charting control

      M 1 Reply Last reply
      0
      • C Cedric Moonen

        Yes, just make it private (or protected).


        Cédric Moonen Software developer
        Charting control

        M Offline
        M Offline
        Maxwell Chen
        wrote on last edited by
        #3

        Then it won't compile.


        Maxwell Chen

        C 1 Reply Last reply
        0
        • M Maxwell Chen

          Then it won't compile.


          Maxwell Chen

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          It won't compile if somebody that uses your class tries to use the copy constructor. So, that was the purpose of his question no ? Preventing people to copy the class. Maybe I misunderstood the question :doh:


          Cédric Moonen Software developer
          Charting control

          M R 2 Replies Last reply
          0
          • C Cedric Moonen

            It won't compile if somebody that uses your class tries to use the copy constructor. So, that was the purpose of his question no ? Preventing people to copy the class. Maybe I misunderstood the question :doh:


            Cédric Moonen Software developer
            Charting control

            M Offline
            M Offline
            Maxwell Chen
            wrote on last edited by
            #5

            Maybe your suggestion is what he needed. I was thinking if he was trying to seek a method which redirects copy ctor to other methods ...


            Maxwell Chen

            T 1 Reply Last reply
            0
            • C Cedric Moonen

              It won't compile if somebody that uses your class tries to use the copy constructor. So, that was the purpose of his question no ? Preventing people to copy the class. Maybe I misunderstood the question :doh:


              Cédric Moonen Software developer
              Charting control

              R Offline
              R Offline
              Roger Stoltz
              wrote on last edited by
              #6

              Cedric Moonen wrote:

              Maybe I misunderstood the question

              I think not. The same guy asked about the Singleton pattern a few threads down and the correct way to implement the Singleton pattern is to declare constructors, copy constructor and the assignment operator as protected or private. A compile time error is expected if the class implemented as a singleton is used in a way it shouldn't. -- Roger


              _It's supposed to be hard, otherwise anybody could do it!

              Regarding CodeProject: "resistance is pointless; you will be assimilated"_

              1 Reply Last reply
              0
              • M Maxwell Chen

                Maybe your suggestion is what he needed. I was thinking if he was trying to seek a method which redirects copy ctor to other methods ...


                Maxwell Chen

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

                Maxwell Chen wrote:

                I was thinking if he was trying to seek a method which redirects copy ctor to other methods ...

                In Other Method! :confused:

                "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
                • S Scorpio

                  can I prevent any copy constructor being called for my class.

                  K Offline
                  K Offline
                  knoxplusplus
                  wrote on last edited by
                  #8

                  Hi !!! If you don't define copy constructor in your class, the compiler creates one automatically. YOu cannot prevent that the compiler creates one, but you can implement one with aan empty body. By !!! -:KNOX:-

                  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