Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question Try putting a SuperInt on the right hand side of an assignment statement using theValue(). Does it work? Why? Take away: nothing too interesting,

Question

  1. Try putting a SuperInt on the right hand side of an assignment statement using theValue(). Does it work? Why?
    • Take away: nothing too interesting, we can return the value of an instance variable. But, in this case we are returning the reference to the variable!
  2. Try putting a SuperInt on the left hand side of an assignment statement using theValue(). Does it work? Why?
    • Take away: First, returning a const type means the function cannot be a l-value. Second, if the the return type is not of const , then, if the receiver of this function is an integer reference, then, the receiver can change this instance variable! Ask me if you don't understand what I mean.

Coding (finish in 20min)

  1. Update the member function theValue() of SuperInt class so that SuperInt can be put on the left hand side of an assignment statement using theValue().
  2. Create a new class "SuperSuperInt," which inherits the "SuperInt" class. Please declare and define this class in separate .h and .cpp files, and DO NOT update SuperInt.h and SuperInt.cpp directly. Please name your new files as "SuperSuperInt.cpp" and "SuperSuperInt.h."
  3. Add one member function theValue() to SuperSuperInt.
  4. Code the member function theValue() of SuperSuperInt to return the value of data member "myValue" in SuperInt. Please make sure the returned value of theValue() CANNOT be put on the left hand side of an assignment statement.image text in transcribed
#include class Super Int { public: // Name helps us see which variable SuperInt(int init, const char *name); - Super Int(); // For demonstrating lvalues //int& theValue(void); const int& theValue(void); private: int myValue; std::string myName; // Neat trick: making this private prevents creating unitialized // objects SuperInt(); #include class Super Int { public: // Name helps us see which variable SuperInt(int init, const char *name); - Super Int(); // For demonstrating lvalues //int& theValue(void); const int& theValue(void); private: int myValue; std::string myName; // Neat trick: making this private prevents creating unitialized // objects SuperInt()

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_2

Step: 3

blur-text-image_3

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

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions