C++ Const parameter modifiers and overloading operators. Thank you! Code to use:
ID: 3821711 • Letter: C
Question
C++ Const parameter modifiers and overloading operators. Thank you!
Code to use: my_int.cc
C++ Const parameter modifiers, overloading operators, and separate compilation 1 Introduction In this lab, you are going to get some practice using const modifiers, overloading operators as friend functions and in order to define a class so that it is an ADT you need to divide the program into separate files. By doing so the programmers who use the type do not have access to how values and operations are implemented. 1.1 Laboratory Preparation Create a directory called L inside your 2400 directory 2. const Parameter Modifier Purpose of this exercise is for you to experience the problems that you can encounter by inconsistent use of the const modifier parameter (pg,638). First copy the following program below: m int.cc Then read and understand the program. After that compile the program and check the error messages. Answer question #1a on the answer sheet. After correcting the problem recompile and run the program. Answer questions ib-ic on the answer sheet. You can find more information on this topic on pages 638 640 3. overloading operators overload the operator as a friend function to the unvoint class. Include the function declaration and the function definition. Also include the necessary statements in the main to test the function you have written. You will have to create two objects of nvainit type with values you choose. Then compare and see whether you're overloaded operator is working correctly. (Don't make any changes to the existing statements i the main function.. Don't forget to include the documentation for this function. Look at question 1d on the answer sheet for the point distribution. For more information, look at pages 644 646 in your text.Explanation / Answer
This code fails to compile because the call to Comparison() is ambiguous. I expect this behavior.
However, when I make either of the Comparison() overloads const, as in: void Comparison(std::string const&) const or void Comparison(CString const&) const (but not both), the code compiles and chooses the non-const overload.
Overload resolution rules are pretty complex and I haven't seen anything that describes how constaffects this situation. My understanding is:
In both cases, 1 & 2 are ambiguous. Can someone explain this? Thanks
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.