Q:

Explain the following code, indicating which definition of Type or initVal is used for each use of those names. Say how you would fix any errors

0

Explain the following code, indicating which definition of Type or initVal is used for each use of those names. Say how you would fix any errors.

typedef string Type;
Type initVal();
class Exercise {
public:
 typedef double Type; Type setVal(Type); Type initVal();
private:
 int val;
};
Type Exercise::setVal(Type parm) {
 val = parm + initVal(); return val;
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <string>

typedef std::string Type;

Type initVal();  // std::string

class Exercise {
public:
  typedef double Type;
  Type setVal(Type);  // double setVal(double)
  Type initVal();  // double initVal()
private:
  int val;
};

Exercise::Type Exercise::setVal(Type parm) {  // double Exercise::setVal(double para)
//Type Exercise::setVal(Type parm) {  // Error: int Exercise::setVal(double para)
  val = parm + initVal();
  return val;
}

Exercise::Type Exercise::initVal() {
  return 0;
}

int main() {
  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now