Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Default copy constructor in c++

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 365
    Comment on it

    A copy constructor is a special type of constructor by using which we can initialize the data members of a newly created object by existing objects. The compiler provides a default copy constructor. 
    Syntax of calling a copy constructor is:

    complex c1 (c2); 

    where complex is name of class, C1 is new object and C2 is existing object.


    class complex
    int r, i;
    public: complex(int a, int b)
       void show();
    complex : : complex(int a, int b)
    {r=a ; i=b;}
    void complex : : show()
    void main()
    int x,y;
    cout<<"Enter real part:"; cin>>x;
    cout<<"Enter imag part:": cin>>y;
    complex C1 (C2);


 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: