Hello,
As in the video it is mentioned that when we are modiefying the value in copied object then both get changed if we make them as poiner variable but I my case. Both stay different. without using deep copy. That means deep copy is not required in this. Why this is happening in my case not in that video.
After chaning the character ‘A’ with ‘C’ both the variables should pointer to 'Cudi’according to video explaination. But in my case it is different.
Below is the code
#include
#include
using namespace std;
class car
{
public:
char carName[20];
int price;
int model_number;
// constructor
car(){
cout<<"This constructor get executed first \n";
}
// Calling the name as the pointer
car(int p, int m, char *c){
price = p;
model_number = m;
strcpy(carName,c);
}
void set_price(){
price = 10;
}
void print_price(){
cout<<"The price of the car "<<carName<<" is "<<price;
}
};
// To access the something of class outside of the class then you need to make it public to access it…
// Task: if the price is more than 5 lac then you will apply the discount of 30%;
int main()
{
car c;
car d(5,2001,“Audi”); // parameterized constructor // I dont think it will be that much helpful
// Code the copy constructor now
car e(d);
d.print_price();
e.carName[0] = 'c';
e.set_price();
cout<<"\n";
e.print_price();
cout<<"\n";
d.print_price();
// Copy constructor copy the the same objects but changing the new one do not affect the old one
// Shallow copy vs deep copy
return 0;
}