Computer Science, asked by 19052, 1 year ago

When a compiler can automatically generate a constructor if it is not defined then why is it considered that writing constructors for a class is a good practice?

Answers

Answered by Cutie1111
1
we need to write copy constructor only when we have pointers or run time allocation of resource like file handle, a network connection, etc (See this)

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above


19052: Something else........
Answered by Atulkrishnan
9
See bro when we do not create a constructor explicitly,then the compiler will generate an implicit constructor automatically and this constructor is equivalent to creating an explicit constructor with no body.So if u want a particular value to be stored/shown in a program for a variable then u should define one with default values.
That's why it is good to define a constructor.Also what is the lose in just defining a constructor if u can write multiple big classes with lots of inheritance,functions etc.
PLZ RATE IT AND MARK AS BRAINLIEST BRO    
Similar questions