在主函数中调用公共函数时出现问题
Issue calling public function in main
我正在尝试在main中调用公共函数validInfixCheck()
,但是在尝试编译时遇到此错误:
g++ calculatorMain.cpp CalculatorExp.cpp
In function `main':
calculatorMain.cpp:(.text+0x99): undefined reference to
`CalculatorExp::validInfixCheck(std::string)'
collect2: error: ld returned 1 exit status
注意:validInfixCheck()
现在不执行任何操作。我只是想确保我可以在主要情况下使用它。
我尝试调用一个没有参数的公共函数来验证这不是问题并且出现相同的错误。
计算器主.cpp
#include "CalculatorExp.h"
#include<iostream>
#include <string>
using namespace std;
//prototype declarations
string getInfixExpression();
int main()
{
CalculatorExp calc;
string inputExpression;
inputExpression = getInfixExpression();
calc.validInfixCheck(inputExpression);
return 0;
}
string getInfixExpression()
{
string exp;
cout<<"Enter infix expression to evaluate: "<<endl;
cin>>exp;
return exp;
}
计算器经验.cpp
#include "CalculatorExp.h"
#include <string>
#include <stack>
using namespace std;
CalculatorExp::CalculatorExp()
{
//default constructor
}
// public //
// valid input check
bool validInfixCheck(string inputExpression)
{
return 0;
}
计算器经验
#ifndef CALCULATOREXP_H
#define CALCULATOREXP_H
#include <string>
#include <stack>
using namespace std;
class CalculatorExp
{
public:
/** Default Constructor;
* @param none
* @pre None*/
CalculatorExp();
/** CONSTANT MEMBER FUNCTIONS*/
/** returns the exp.
/* @pre None
/* @post The value returned is the exp*/
string get_exp( ) const { return exp; }
/** FUNCTIONS*/
/** returns true if exp is validated.
/* @pre None
/* @post The value returned is true if exp is validated.*/
bool validInfixCheck(string inputExpression);
private:
/** expression*/
string exp;
};
#endif
您已在 CalculatorExp.h 中声明 validInfixCheck(( 作为类 CalculatorExp 的方法。但是,您尚未将此函数定义为类的成员,因为您在定义中省略了类名前缀。因此,请在 CalculatorExp.cpp 中进行此更改:
bool CalculatorExp::validInfixCheck(string inputExpression)
{
return 0;
}
相关文章:
- 类C++中的函数问题(LNK2019和LNK1120错误)
- 返回不停止函数,递归函数问题?(编程练习,动态规划,Levenshtein 回溯)
- 变分模板递归构造函数问题
- C++函数问题中的数组分配
- C++中嵌套在另一个 LinkedList 中的 LinkedList 整数上的回调函数问题
- C++重载构造函数问题
- 二叉搜索树析构函数问题
- C++ vector<pair<int,int>> std::all_of() 函数问题(重定向到头文件)
- 迷宫构造函数问题 [线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x8)]
- C++函数问题中的 IF 语句
- 函数问题,未定义的引用错误
- C++ 指针无效函数问题
- C++函数问题 = 帮助我理解基本概念
- 由于基于接口的编程,遇到 C++ 虚拟模板函数问题
- C++二进制树递归析构函数问题
- 构造函数问题<无法读取内存>
- 构造函数问题
- C 时间函数问题
- 另一个类中的类的构造函数问题
- C与C++函数问题