why are we initializing tyres in every constructor ?
In const list ? initializing part?
when we create object of a class
it’s member will have garbages so we have to initialize it
for initializing the const variable we have to write like
car():tyres(4)
what it will do it will intialize tyre with 4
this thing you cann;t do inside constructor nor while declaring as memory is allocating in runtime
i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course
why can’t we declare constant members inside constructor and while declaring as memory ??
constant member are those whose value can not changed once initialised
and they are intilized at the time of making object of class and at the same time constructor is called
we want to intialise it with 4
so we have to it before entering constructor
and we can do it like
car():tyres(4)
this is not assinging 4 to tyres rather it is intialising it with 4
but when we do
car(){
tyers=4;
}
it is assinging 4 to tyers which is not allowed for const variables
i hope this helps
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.