Thread: header file using a string in a class

  1. #1
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198

    header file using a string in a class

    i'm working on a project to make a simple blackjack game. so far i am at the point where i should be testing out my card class to see if it's working and everything. i have 3 files, card.h:
    Code:
    enum cardsuit {HEARTS, DIAMONDS, CLUBS, SPADES};
    
    class card
    {
    public:
        card();
        void Set_Card(int);
        void Display();
        int Card_Value();
        void Swap_Card(card);
    
    private:
        string description;
        int value;
        cardsuit suit;
    };
    then there's card.cpp which has all the function def's:
    Code:
    #include <iostream>
    #include <string>
    #include "card.h"
    using namespace std;
    
    card::card()
    {
    // initialize card
    }
    
    int card::Card_Value()
    {
        return value;
    }
    
    void card::Display()
    {
    // display card info
    }
    
    void card::Set_Card(int num)
    {
    // set the card depending on the num
    }
    
    void card::Swap_Card(card new_card)
    {
    // swap current card with the new_card
    }
    and then my main program so far just tests out the linkage and the display function:
    Code:
    #include <iostream>
    #include <string>
    #include "card.h"
    using namespace std;
    
    int main()
    {
        card cardobject;
    
        cardobject.Display();
    
        cin.get();
        return 0;
    }
    i'm using Dev-Cpp and it tells me "string is used as a type but is not defined as a type" in my card.h file. then it says undeclared variable whenever i try to use the "description" variable... any thoughts? what do i have to do to be able to declare a string variable in a class in a header file? thanks for the help
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

  2. #2
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    wait wait wait I think I got it... had to either add "using namespace std" to the header file, or just do a "std::" in front of the string declaration. sorry for such a huge post on such a small fix haha
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM