if compiler defines its own default constructor why do we have to define our own constructors
Answers
Explanation:
In C++, compiler creates a default constructor if we don’t define our own constructor (See this). Compiler created default constructor has empty body, i.e., it doesn’t assign default values to data members (In java, default constructors assign default values).
Compiler also creates a copy constructor if we don’t write our own copy constructor. Unlike default constructor, body of copy constructor created by compiler is not empty, it copies all data members of passed object to the object which is being created.
ᴀɴsᴡᴇʀ:
ɪɴ ᴄ++, ᴄᴏᴍᴘɪʟᴇʀ ᴄʀᴇᴀᴛᴇs ᴀ ᴅᴇғᴀᴜʟᴛ ᴄᴏɴsᴛʀᴜᴄᴛᴏʀ ɪғ ᴡᴇ ᴅᴏɴ'ᴛ ᴅᴇғɪɴᴇ ᴏᴜʀ ᴏᴡɴ ᴄᴏɴsᴛʀᴜᴄᴛᴏʀ (sᴇᴇ ᴛʜɪs). ... ᴜɴʟɪᴋᴇ ᴅᴇғᴀᴜʟᴛ ᴄᴏɴsᴛʀᴜᴄᴛᴏʀ, ʙᴏᴅʏ ᴏғ ᴄᴏᴘʏ ᴄᴏɴsᴛʀᴜᴄᴛᴏʀ ᴄʀᴇᴀᴛᴇᴅ ʙʏ ᴄᴏᴍᴘɪʟᴇʀ ɪs ɴᴏᴛ ᴇᴍᴘᴛʏ, ɪᴛ ᴄᴏᴘɪᴇs ᴀʟʟ ᴅᴀᴛᴀ ᴍᴇᴍʙᴇʀs ᴏғ ᴘᴀssᴇᴅ ᴏʙᴊᴇᴄᴛ ᴛᴏ ᴛʜᴇ ᴏʙᴊᴇᴄᴛ ᴡʜɪᴄʜ ɪs ʙᴇɪɴɢ ᴄʀᴇᴀᴛᴇᴅ.