2

Ok I know there are millions of variations of this particular problem, and I have tried (desperately) to go through them all and see if they apply, to no avail.

Currently I'm trying to declare a deque in a header file, and the damn thing wont let me due to the error mentioned. The same thing happens to me in a lot of my projects, and I think its just something basic I'm lacking in my knowledge of c++ class syntax.

main.cpp

#include <iostream>
#include <fstream>
#include <string>
#include <deque>
#include "Card.h"
#include "random.h"

using namespace std;

void            createloop();
int             get_option();
deque <Card>    make_new_deck();
deque <Card>    load_new_deck();

int main()
{
    createloop();
    return 0;
}

I havn't shown the rest of the file for clarities sake, and im pretty confident it isnt the problem. The error appears in Card.h:

Card.h

#ifndef CARD_H
#define CARD_H

class Card
{
    public:
        Card();

        deque<string> param_name_deque;
        deque<double> param_value_deque;
        virtual ~Card();
    protected:
    private:
};

#endif // CARD_H

card.cpp

#include "Card.h"


Card::Card()
{
    //ctor
}

Card::~Card()
{
    //dtor
}

To anyone who can help - thanks in advance! Ill be very happy when I understand whats wrong here!!!

2 Answers2

6

You have to include both std::deque and std::string in your header file card.h

#include <string>
#include <deque>

Meanwhile,

deque<string> param_name_deque;
deque<double> param_value_deque;

should be

std::deque<std::string> param_name_deque;
std::deque<double> param_value_deque;
taocp
  • 23,276
  • 10
  • 49
  • 62
  • ahhhh forgot to write "using namespace std"! Totally forgot you had to identify your namespace in haeder files - staggeringly stupid of me. – Owen McConnell Apr 10 '13 at 09:45
  • @OwenMcConnell - not writing `using namespace std;` is correct. What you forgot is to qualify the names with `std::`. Don't get in the habit of blasting everything into the global namespace; there are good reasons for having these things in their own namespace. – Pete Becker Apr 10 '13 at 15:01
3

You need to specify the namespace in card.h when you declare the param_name_deque and param_value_deque:

std::deque<std::string> param_name_deque;
std::deque<double> param_value_deque;

and include the proper headers:

#include <string>
#include <deque>

I would avoid using namespace std, it may seem convenient but it will eventually cause you problems.

Community
  • 1
  • 1
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740