Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: vector does not name a type

Tags:

c++

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. 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:

 #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 
like image 426
Chris De Bow Avatar asked Dec 06 '11 16:12

Chris De Bow


People also ask

What does vector does not name a type mean?

The reason the compiler says “vector is not a type” is that vector is not a type. It's a template from which types can be made.

What is not name a type error in CPP?

Note that you can also get this error if you place an extern reference to a declaration in a . h / . hpp file before the class is defined, even when you have the actual declaration after the . h / .

How do you add to a vector in C++?

Appending to a vector means adding one or more elements at the back of the vector. The C++ vector has member functions. The member functions that can be used for appending are: push_back(), insert() and emplace(). The official function to be used to append is push_back().

How do I remove something from a vector in C++?

The C++ vector has many member functions. Two of these member functions are erase() and pop_back(). pop_back() removes the last element from the vector. In order to remove all the elements from the vector, using pop_back(), the pop_back() function has to be repeated the number of times there are elements.


1 Answers

You forgot to add std:: namespace prefix to vector class name.

like image 176
Hauleth Avatar answered Sep 18 '22 17:09

Hauleth