Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What happens if you forget the const in an accessor function (an accessor queries the object for information without changing any of the data members)?

What happens if you forget the const in an accessor function (an accessor queries the object for information without changing any of the data members)? What happens if you accidentally supply a const in a mutator function (a mutator is a function that modifies the data members of the object)? Answer (no const in an accessor): Answer (const in a mutator):

Sol56:

If you forget the const in an accessor function, the compiler may give you an error if you try to call the function on a const object. This is because the compiler considers the function as modifying the object, which is not allowed for const objects. Adding const to the function signature is a way to tell the compiler that the function is only accessing (and not modifying) the data members.

If you accidentally supply a const in a mutator function, the compiler will give you an error because the function is not allowed to modify the object\'s data members when it is marked as const. The const keyword tells the compiler that the function should not change the object\'s state, so it won\'t allow any modifications to be made. This error can be fixed by removing the const keyword from the function signature.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Android Graphics

Authors: Wallace Jackson

1st Edition

1430257857, 978-1430257851

More Books

Students also viewed these Programming questions

Question

What does the tkinter modules mainloop function do?

Answered: 1 week ago

Question

Keep descriptions and explanations brief.

Answered: 1 week ago