Lecture-12 Copy constructor introductory implementation using c++ | Advance C++ Series

Karan IITgn569 words

Full Transcript

hi all this is me Curren so in this particular lecture we are going to talk about copy Constructor how we create another object using already created object so here I have taken strategy class and this class contains three private member variables that is order quantity price and account name I have already defined the strategy class Constructor this Constructor will take three parameters that is quantity price and name and it will initialize all the private member variables using the value provided by the programmer and here I have taken another function that is print member variables this particular function will print member variables associated with some particular object so let's see let's create create first object strategy object one and here I providing order quantity equal to let's say 10 and price equal to 100 and name equal to let's say current and let's print the value associated with object one so this will print the value associated with this particular object object one and here I should get value like 10 100 and current now I am trying to create another object strategy object 2 using already created object object one so this is how I will create object two using already created object 1 so if I print member variables associated with object 2 then I can do this so let's see how the values looks like code has compiled successfully here I can see order quantity 10 price is 100 of account name is current and this is coming from here like object one contains quantity equal to 10 price equal to 100 and account name equal to current and here I can see order quantity 10 price equal to 100 and account name equal to current and these are the values asso associated with this particular object object two because object two has been created by object one and in this particular case when we are creating object two using object one in this fashion then copy Constructor is going to called and that copy Constructor will copy all the values of member variables associated with object one to object two so if we try to understand how all the things are working so we have created the object one by providing the values to the member variables now we are printing the value of all the member variables and in this case we'll get we'll get 10 100 and current now I have created another object object 2 using object one and in this case compiler will call cop copy Constructor and that copy Constructor will copy all the values of private member variables from object one to object two so that is why we are seeing 10 100 and current when we are trying to print the value of member variables associated with object two so in this case compiler is calling copy Constructor and that copy Constructor is copying all the private member variables from object one to object two and at the end we have printed the value of all the private member variables associated with object two so this is how we can create another object using already created object and in this case our compiler is going to call Copy Constructor to copy the values from object one to object two so let's meet in the next Le in which we'll talk about some other topic

Need a transcript for another video?

Get free YouTube transcripts with timestamps, translation, and download options.

Transcript content is sourced from YouTube's auto-generated captions or AI transcription. All video content belongs to the original creators. Terms of Service · DMCA Contact

Lecture-12 Copy constructor introductory implementation u...