简体   繁体   English

错误:vector没有命名类型

[英]Error: vector does not name a type

I'm having lots of errors in my final project (a poker and black jack sim). 我的最终项目(扑克和黑色插孔​​卡片)中有很多错误。 I'm using a vector to implement the "hands" in the blackJack class, and I'm using a structured data type declared in another class, which is publicly inherited. 我正在使用向量来实现blackJack类中的“hands”,我正在使用在另一个类中声明的结构化数据类型,这是公开继承的。 The error I'm worried about is the compiler I'm using telling me that I'm not declaring a type in the vector. 我担心的错误是我正在使用的编译器告诉我,我没有在向量中声明一个类型。

blackJack header file: blackJack头文件:

 #ifndef BLACKJACK_H
 #define BLACKJACK_H
 #include <vector>
 #include "card.h"

 class blackJack: public cards
 {
 private:
    vector <Acard> playerHand;
    vector <Acard> dealerHand;

 public:
    blackJack();
    void dealHands();
    void hitOrStay();
    void dealerHit();
    int handleReward(int);
    void printHands();
 };
 #endif 

card header file (this is the class black jack inherits from): 卡头文件(这是黑杰克继承的类):

 #ifndef CARD_H
 #define CARD_H

 const char club[] = "\xe2\x99\xa3";
 const char heart[] = "\xe2\x99\xa5";
 const char spade[] = "\xe2\x99\xa0";
 const char diamond[] = "\xe2\x99\xa6";
 //structured data to hold card information
 //including:
 // a number, representing Ace-King (aces low)
 //a character, representing the card's suit
 struct Acard
 {
   int number;
   char pic[4];
 };



 // a class to hold information regarding a deck of cards
 //including:
 //An array of 52 Acard datatypes, representing our Deck
 //an index to the next card in the array
 //a constructor initializing the array indices to Ace-king in each suit
 //a function using random numbers to shuffle our deck of cards
 //13 void functions to print each card
 class cards
 {
  private:
    Acard Deck[52];
    int NextCard;
  public:
    cards();
    Acard getCard();
    void shuffleDeck();
    void cardAce(char[]);
    void cardTwo(char[]);
    void cardThree(char[]);
    void cardFour(char[]);
    void cardFive(char[]);
    void cardSix(char[]);
    void cardSeven(char[]);
    void cardEight(char[]);
    void cardNine(char[]);
    void cardTen(char[]);
    void cardJack(char[]);
    void cardQueen(char[]);
    void cardKing(char[]);

 };

 #endif

您忘了将std:: namespace前缀添加到vector类名称。

use: 采用:

std::vector <Acard> playerHand;

everywhere qualify it by std:: 到处都有资格通过std::

or do: 或做:

using std::vector;

in your cpp file. 在你的cpp文件中。

You have to do this because vector is defined in the std namespace and you do not tell your program to find it in std namespace, you need to tell that. 你必须这样做,因为vector是在std命名空间中定义的,你不告诉你的程序在std命名空间中找到它,你需要告诉它。

您需要使用其命名空间( std )限定vector ,或者在CPP文件的顶部导入命名空间:

using namespace std;

Also you can add #include<vector> in the header. 您还可以在标题中添加#include<vector> When two of the above solutions don't work. 当上述两种解决方案不起作用时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM