https://ide.codingblocks.com/s/41670
sir, i dont think line no. 10,11,12 is necessary in the code .the code should work without line no 10,11,12…but it shows error. …is assigning name pointer to null necessary???
Https://ide.codingblocks.com/s/41670
When we create a parameterized constructor then in C++ we have to explicitly specifie a default constructor. Default constructor is specified implicitly by C++ only when no parameteized constructor is created.
Hence without 10,11,12 line it shows a error.
sir actually i m not getting what you are saying… can you explain it more…thanks
In C++ their are two types of constructor
- Default constructor :- no parameter passed in constructor
- paramterized constructor :- some parameter passed in constructor
Default constructor if not created by user, are created by the compiler but, only when no parameterized constructor is created by the user.
Hence is you program as you have created a paramterized constructor you have to create a default constructor.
if you remove the paramterized constructor then their is no need to declare a default constructor
I hope this helps
pardon me …but i dont think i have created paramaterised constructor…
car (){
name=NULL;
} // Default
car(car &e){
price =e.price;
model=e.model;
int l=strlen(e.name);
name=new char[l+1];
strcpy(name,e.name);
}// Parameterised
but it is copy constructor…
copy constructor is a parameterized constructor…you are passing arguments in that.
(Extra Note: copy constructor is also implicitly defined you run your code without creating it)
okay…i got it properly …thank you sir