2011-12-06 23 views
17

私は最終プロジェクト(ポーカーとブラックジャックのシム)で多くのエラーが発生しています。私はvectorを使ってblackJackクラスに "hands"を実装しています。他のクラスで宣言されている構造化データ型を使用しています。私が心配しているエラーは、私がベクトルの型を宣言していないと言っているコンパイラです。エラー:ベクトルにタイプがありません

ブラックジャックのヘッダファイル:

#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 

カードヘッダーファイル(これはブラックジャックから継承するクラスである):

#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 

答えて

15

使用:

std::vector <Acard> playerHand; 

至る所std::によりそれを修飾します

または:

using std::vector; 

あなたのcppファイルに含まれています。

vectorstd名前空間に定義されていて、プログラムにstd名前空間でそれを見つけるよう指示していないので、これを行う必要があります。

47

std::名前空間プレフィックスをvectorクラス名に追加するのを忘れた。

9

あなたは(stdである)、その名前空間にvectorを修飾、またはあなたのCPPファイルの先頭に名前空間をインポートするか必要があります。

using namespace std; 
+8

間違いありません。しかし、これをしないでください。 –

+1

Uはソースファイルでのみこれを行うことができます。ヘッダーにはないので、Uは非常に悪いことです(私はいくつかのスパゲッティを意味します)。 – Hauleth

+0

@LokiAstariなぜこれをしないのですか?これは「名前空間を使用している」ものではありませんか?またはあなたのネームスペースをstdからすべてのもので氾濫させることに問題がありますか? (私は議論していない、私はCを学んでいる+ +) –

8

また、あなたは、ヘッダーに#include<vector>を追加することができます。上記の2つの解決法が機能しない場合。

+1

何らかの理由でベクトルは私のヘッダーファイルに含まれている場合のみ動作します。ソースファイルに入れても機能しません。この方法で動作するのは唯一のファイルです。どうして? – JoeManiaci