【发布时间】:2014-03-23 02:16:02
【问题描述】:
我的老师给我的班级提供了一个程序,可以将像 A+B*C 这样的中缀表达式转换为后缀。我已经完成了其他代码,但是重载的 istream 运算符给了我一些问题。这是我得到的错误:
错误:“convertToPostfix”没有依赖于模板参数的参数,因此“convertToPostfix”的声明必须可用[-fpermissive]|
这是 istream 运算符的代码:
template <class U>
std::istream& operator>>(std::istream& in, expression<U>& e) {
char c;
e.ifix ="";
e.pfix ="";
do {
in >> e;
e.pfix += c;
}while(c!='.' || c!=';');
convertToPostfix();
return in;
}
我的老师告诉我们将 convertToPostfix 放在 return 语句之前,以便它同时返回中缀和后缀表达式。我正在寻找代码正确性作为反馈。提前感谢您为我提供的任何帮助。
【问题讨论】:
标签: templates operator-overloading postfix-notation infix-notation