矢量未知大小

t3r*_*2d2 1 c++ vector header-files c++11

我有一个 Player 类,其中包含一个实例变量:\

vector<Card> userCards;
Run Code Online (Sandbox Code Playgroud)

为了避免任何编译错误,我向前声明了该类Card。但是现在当我尝试构建解决方案时,我收到一条错误消息

卡*:尺寸未知。

基本上我试图创建一个Player包含非固定数量的卡片的 who,所以我尝试使用向量,但现在我无法让它工作。

播放器.h

#include <iostream>
#include <vector>

using std::string;
using std::vector;

#ifndef PLAYER_H_
#define PLAYER_H_

class Card;
class Player {
private:
    vector<Card> userCards;
};
#endif
Run Code Online (Sandbox Code Playgroud)

卡.h

#include <iostream>

using std::string;

#ifndef CARD_H_
#define CARD_H_

class Card {
private:
    string name;
    string type;

public:
    Card(const string& name, const string& type);   
};
#endif
Run Code Online (Sandbox Code Playgroud)

我有一堆不相关的不同功能,所以我没有包括它们。

Log*_*uff 5

的类型模板参数std::vector不能是不完整类型。它必须在实例化之前定义(完整)std::vector<Card>。为此,请将前向声明替换class Card;#include "Card.h"指令。

您可以在此处查看对模板参数的进一步要求。