默认构造函数中未识别的标识符

Identifier Unidentified in Default Constructor

本文关键字:标识符 识别 构造函数 默认      更新时间:2023-10-16

我一直在网上搜索如何解决这个问题。我也试着公开一切,但我认为这不是问题所在。这是我的标题代码:

#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;

这可能是您的错误来源,尽管这一行也应该有一条错误消息。

接下来,该对是一对intchar。但你稍后会写:

pair<int, char> (i, suitValue[j])

suitValue[j]char *,而不是char。所以这也必须产生一个编译器错误。我想你想要std::string而不是charconst char *

此外,您可以在j循环中访问越界。对于维度为4的数组,有效索引为0 1 2 3。不是4