练习7.34
程序会出错,显示语法错误,标识符pos;
练习7.35
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 typedef string Type; 6 Type initVal(); //string,原题这里有问题,没有定义,只有声明 7 class Exercise { 8 public: 9 typedef double Type; //隐藏了外层作用域的类型别名 10 Type setVal(Type); //double setVal(double); 11 Type initVal(); //double,原题这里没有定义 12 private: 13 int val; 14 }; 15 16 Exercise::Type Exercise::setVal(Type parm) //原题这里前面的返回类型有歧义,如果是上面的Type会出错,应该用作用域运算符限定于类中 17 { 18 val = parm + initVal(); //使用的是类里面的成员函数 19 return val; 20 } 21 22 Exercise::Type Exercise::initVal() 23 { 24 return 0; 25 } 26 27 Type initVal() 28 { 29 return "hello world"; 30 }