c++ - 当我有一个与当前类中使用的值相同的枚举时,如何使用另一个类的枚举?C++
问题描述
我无法返回一个要求我从头等舱返回枚举“BEGIN”的函数。我遇到的问题是我正在使用的当前类中使用单独的枚举列表。因此,当我返回函数时,它是从当前类而不是派生类中获取的。有人知道怎么修这个东西吗?头类:
enum Token {
PRINT, BEGIN, END, IF, THEN}
LexItem(Token token, string lexeme, int line) {
this->token = token;
this->lexeme = lexeme;
this->lnum = line;
}
函数类:
LexItem getNextToken(istream& in, int& linenum){
enum TokState { BEGIN, INID, INSTRING, ININT, INREAL, INCOMMENT, SIGN }
if(lexeme.compare("begin")){
LexItem item = LexItem(BEGIN, lexeme, linenum); //error on LexItem no instance of constructor
return item;}
我认为这是因为它使用 TokState begin 而不是来自 Token 的。不知道如何修复。我无法更改任一类中的枚举。
解决方案
推荐阅读
- google-cloud-platform - 如何在谷歌云数据流管道中传递动态参数
- java - 从 jodatime DateTime 中提取时区
- ios - 如何通过 indexPath 在水平 collectionView 中动态添加视图/图层
- database - Posgresql 创建表使用信息_schema
- android - 资源目录导航无效
- javascript - 将数据从 Javascript 发送回 Python
- c# - 在 Unity 中将 Sprite 数组更改为 GameObject 数组
- javascript - 使用来自 Web 服务的 SAPUI5 和 SOAP 请求和响应
- python - Python RecursionError : Pandas.eval() 的简单操作崩溃
- jenkins - Jenkins 没有从 Workspace 中的 Katalon 测试创建 JUnit 测试报告