【发布时间】:2014-08-04 19:20:38
【问题描述】:
我收到一条错误消息:
error: no matching function for call to 'Expression::shuntingYard(Expression&)'
当函数在名为 Expression.h 的头文件夹中声明时。我看不出有什么问题。我还包括了所有必要的预处理器指令。
包括以下文件:
main.cpp
#include <iostream>
#include "Expression.h"
using namespace std;
int main()
{
Expression expr("2 * (3 + 1)");
//Set x = 5
//expr.instantiateVariable('x',5);
//Set y = 3
//expr.instantiateVariable('y',3);
cout << "Answer: " << expr.shuntingYard(expr) << endl;
}
表达式.h
#ifndef EXPRESSION_H
#define EXPRESSION_H
#include <string>
#include <iostream>
using namespace std;
class Expression
{
private:
string expression;
public:
Expression(string expr);
~Expression();
void instantiateVariable(char name, int value);
//Function to calculate the postFix string made by the ShuntingYard function
int evaluate(string, int, int);
//Function to convert infix expression to postfix
string shuntingYard(string);
//Other
int higherPrecedence(char operator1, char operator2);
bool IsOperator(char C);
bool IsOperand(char C);
};
#endif
如果您能指出我做错了什么,收到此错误,我将不胜感激。
谢谢。
【问题讨论】:
-
所以你没有这样的函数签名,你也没有提供从
Expression到std::string的任何自动转换。
标签: c++ function class object compiler-errors