programs of Copy constructor :
#include<iostream> #include<stdlib.h> using namespace std; class abc{ int a; public: abc(){} void set_a(){ a=10; } abc(abc &obj){ // pass the object references a=obj.a; } int get_a(){ // return the veriable return a; } }; int main(){ abc st; st.set_a(); abc std(st); cout<<std.get_a(); }
10
If you like code with vibhu and would like to contribute, you can also write an article using This link :
https://docs.google.com/forms/d/e/1FAIpQLScAmvlPvNUz35R-G0nc_zpRVP3o8xlhtFgC3aKPyLetX_RyXg/viewform?pli=1
OR mail your article to codewithvibhu@gmail.com. See your article appearing on the code with vibhu main page and help other students.
0 Comments