
Brock T.
asked 03/01/22Const Member Functions The code given below does not compile due to const issues.
Modify the existing class code and add const in the appropriate locations to make it compile with the existing main and printNumber
1 Expert Answer

Zachary M. answered 03/01/22
Full Time Software Engineer and Chess Hobbiest
If you try to compile that code, you will see the error:
This is telling you that the call to the "getValue" function is failing because that function is not declared as const, but the instance of the EvenNumber class is a const. The failure happens because Non-const functions can only be called by non-const objects. However, when a function is declared as const, it can be called on any type of object.
In order to fix this error, all we need to do is add the "const" keyword to the getValue() function definition.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Zachary M.
What language is this supposed to be in?03/01/22