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
help
8 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.
  • S Offline
    S Offline
    Subramaniam s V
    wrote on last edited by
    #1

    Hi, can anyone please help me out in understanding COPY CONSTRUCTOR..please clarify me on the following questions.. 1. What a COPY CONSTRUCTOR actually does and when it is used.. 2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default).. 3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR.. if there are any interesting materials on these topics do let me know as I am getting much confused on the usage of these concepts.. Thanks In Advance

    S L 2 Replies Last reply
    0
    • S Subramaniam s V

      Hi, can anyone please help me out in understanding COPY CONSTRUCTOR..please clarify me on the following questions.. 1. What a COPY CONSTRUCTOR actually does and when it is used.. 2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default).. 3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR.. if there are any interesting materials on these topics do let me know as I am getting much confused on the usage of these concepts.. Thanks In Advance

      S Offline
      S Offline
      Sarath C
      wrote on last edited by
      #2

      Check this link http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html SaRath

      1 Reply Last reply
      0
      • S Subramaniam s V

        Hi, can anyone please help me out in understanding COPY CONSTRUCTOR..please clarify me on the following questions.. 1. What a COPY CONSTRUCTOR actually does and when it is used.. 2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default).. 3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR.. if there are any interesting materials on these topics do let me know as I am getting much confused on the usage of these concepts.. Thanks In Advance

        L Offline
        L Offline
        Laxman Auti
        wrote on last edited by
        #3

        Subramaniam wrote:

        1. What a COPY CONSTRUCTOR actually does and when it is used..

        It is used to copy the contents of the Existing object to new born object

        Subramaniam wrote:

        2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default)..

        When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied

        Subramaniam wrote:

        3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR..

        Assignment operator initialises the existing object by another existing object Copy constructer initialises the new born object by existing object for e.g CDemo d2; CDemo d=d2; //copy constructer CDemo d1(d2); //copy constructer CDemo d3; d3=d2; //Assignment operator Knock out 't' from can't, You can if you think you can :cool:

        J S 2 Replies Last reply
        0
        • L Laxman Auti

          Subramaniam wrote:

          1. What a COPY CONSTRUCTOR actually does and when it is used..

          It is used to copy the contents of the Existing object to new born object

          Subramaniam wrote:

          2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default)..

          When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied

          Subramaniam wrote:

          3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR..

          Assignment operator initialises the existing object by another existing object Copy constructer initialises the new born object by existing object for e.g CDemo d2; CDemo d=d2; //copy constructer CDemo d1(d2); //copy constructer CDemo d3; d3=d2; //Assignment operator Knock out 't' from can't, You can if you think you can :cool:

          J Offline
          J Offline
          Jax_qqq
          wrote on last edited by
          #4

          Hei Laxman r u giving Interview or what... Hahaha Anuj Kamthan Software Developer

          L T 2 Replies Last reply
          0
          • L Laxman Auti

            Subramaniam wrote:

            1. What a COPY CONSTRUCTOR actually does and when it is used..

            It is used to copy the contents of the Existing object to new born object

            Subramaniam wrote:

            2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default)..

            When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied

            Subramaniam wrote:

            3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR..

            Assignment operator initialises the existing object by another existing object Copy constructer initialises the new born object by existing object for e.g CDemo d2; CDemo d=d2; //copy constructer CDemo d1(d2); //copy constructer CDemo d3; d3=d2; //Assignment operator Knock out 't' from can't, You can if you think you can :cool:

            S Offline
            S Offline
            Subramaniam s V
            wrote on last edited by
            #5

            Thanks. can you be more elaborate on the following comments given by you.. "When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied" Thanks

            L 1 Reply Last reply
            0
            • S Subramaniam s V

              Thanks. can you be more elaborate on the following comments given by you.. "When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied" Thanks

              L Offline
              L Offline
              Laxman Auti
              wrote on last edited by
              #6

              Subramaniam wrote:

              "When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied"

              See the following example

              class CDemo
              {
              int i;
              CDemo(CDemo &b)
              {
              i=b.i;
              };
              public:

              CDemo& operator=(const CDemo &b)
              {
              	this->i=b.i;
              	return \*this;
              };
              
              CDemo(){}; //public constructer
              
              CDemo test()
              {
              	return \*this;
              }
              

              };
              int main(int argc, char* argv[])
              {
              CDemo c;
              c=c.test();
              CDemo c1(c); //not allowed
              CDemo c2=c; //even this also not allowed.
              return 0;
              }

              With this we can prevent public from making copy of the objects only class members are allowed to make such coping :) Knock out 't' from can't, You can if you think you can :cool:

              1 Reply Last reply
              0
              • J Jax_qqq

                Hei Laxman r u giving Interview or what... Hahaha Anuj Kamthan Software Developer

                L Offline
                L Offline
                Laxman Auti
                wrote on last edited by
                #7

                Jax_qqq wrote:

                Hei Laxman r u giving Interview or what...

                No, i am learning C++ with CP. :) Knock out 't' from can't, You can if you think you can :cool:

                1 Reply Last reply
                0
                • J Jax_qqq

                  Hei Laxman r u giving Interview or what... Hahaha Anuj Kamthan Software Developer

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

                  Jax_qqq wrote:

                  Hei Laxman r u giving Interview or wha

                  Hope so!... humm.. i am waiting for your answer

                  "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
                  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