#include<iostream.h>
class vector
{
public:
int *a;
int b;
//default constructor
vector()
{
a = new int;
*a=10;
}
//parameterized constructor
vector(int k)
{
a = new int;
*a=k;
}
void getvalue()
{
cout<<"a="<<*a<<"\n";
}
//copy constructor
vector(vector &v)
{
a = new int;
*a=*v.a;
}
};
void main()
{
vector vector1; //invoke default constructor
vector1.getvalue();
vector vector2(25); //invoke parameterized constructor
vector.getvalue();
vector vector3;
vector vector4(vector3); //invoke copy constructor
vector4.getvalue();
}
output
a=10
a=25
a=10
class vector
{
public:
int *a;
int b;
//default constructor
vector()
{
a = new int;
*a=10;
}
//parameterized constructor
vector(int k)
{
a = new int;
*a=k;
}
void getvalue()
{
cout<<"a="<<*a<<"\n";
}
//copy constructor
vector(vector &v)
{
a = new int;
*a=*v.a;
}
};
void main()
{
vector vector1; //invoke default constructor
vector1.getvalue();
vector vector2(25); //invoke parameterized constructor
vector.getvalue();
vector vector3;
vector vector4(vector3); //invoke copy constructor
vector4.getvalue();
}
output
a=10
a=25
a=10
No comments:
Post a Comment