默认构造函数中未识别的标识符
Identifier Unidentified in Default Constructor
我一直在网上搜索如何解决这个问题。我也试着公开一切,但我认为这不是问题所在。这是我的标题代码:
#ifndef DEALER_HPP
#define DEALER_HPP
#include <queue>
class Dealer{
private:
queue<pair<int, char>> deck;
public:
Dealer(); // default constructor
~Dealer(); // destructor
};
#endif
源文件:
#include "Dealer.hpp"
using namespace std;
Dealer::Dealer(){// create unshuffled deck
const char* suitValue[4] = {"c", "d", "h", "s"};
for (int i = 2; i <= 14; i++)
{
for (int j = 1; j <= 4; j++)
{
deck.push(pair<int, char> (i, suitValue[j])); // error on this line
}
}
}
我的源文件中有一个错误
标识符"deck"未识别。
知道怎么修吗?我也尝试过使用make_pair,但没有成功。我真的觉得我的代码应该可以工作,我确信有一些简单的错误。对不起,我找不到这个。
首先需要#include <utility>
,deck
的声明应该是:
std::queue< std::pair<int, char> > deck;
这可能是您的错误来源,尽管这一行也应该有一条错误消息。
接下来,该对是一对int
和char
。但你稍后会写:
pair<int, char> (i, suitValue[j])
suitValue[j]
是char *
,而不是char
。所以这也必须产生一个编译器错误。我想你想要std::string
而不是char
和const char *
。
此外,您可以在j
循环中访问越界。对于维度为4
的数组,有效索引为0
1
2
3
。不是4
。
相关文章:
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 提升 ASIO 无法识别计时器对象
- 从udp接收帧对于人脸识别来说太慢
- 模板类无法识别友元运算符
- #ifdef和未声明的标识符
- std::visit无法识别类型
- f2、f3、f4标识符未找到
- 无法识别模板功能
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- 设置 Visual Studio for MPI: 找不到标识符错误
- 如何在LLVM中dyn_cast以识别StoreInst?
- 未声明的标识符编译暗黑破坏神 2 程序"muleview"
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- Google protobuf 时间戳未声明标识符,在 Windows 上具有C++
- 从不同的附加依赖项中识别等同命名的函数
- 是否有一种工具可以识别一组C++源文件所指的外部标识符
- 识别标识符为的派生类不起作用
- 无法识别bad_alloc标识符
- 错误:标识符:"SHGetKnownFolderPath"无法识别
- 默认构造函数中未识别的标识符