I want to assign one class object to another class object in c++.
Ex: There is one class Dog and another class Cat. Create one one instance of each (d1 & c1). Don't want to use any STL. I want to use this statement in my code
d1 = c1;
Program
class dog
{
char dc;
float df;
int di;
public:
void setdata2(char c, float f, int i)
{ dc = c; df = f; di = i; }
void showdata2()
{ cout <<"char =" << dc <<", float =" << df <<", int =" << di <<endl; }
};
class cat
{
float cf;
int ci;
char cc;
public:
void setdata(float f, int i, char c)
{ cf = f; ci = i; cc = c; }
void showdata()
{ cout <<"float =" << cf <<", int =" << ci <<", char =" << cc <<endl; }
};
int main()
{
dog d1, d2;
cat c1, c2;
d1.setdata2('A', 56.78, 30);
c1.setdata(12.34, 2, 3);
d1.showdata2();
c1.showdata();
d2 = c1; // Question 1
dog d3(c1); // Question 2
dog d4 = c1; // Question 3
return 0;
}
Please answer Question 1/2/3 each separately.