samedi 27 juin 2015

Error when adding typedef in header

I'm new to C++, and I'm learning from Accelerated C++ (for anyone with the book, I'm trying to run the program described in §7.4)

The program I'm looking at uses some typedefs - I gather that if I add these to a header file, any source file which includes that header will be able to use the typedefs too.

My header is:

#ifndef READ_GRAMMAR_H_INCLUDED
#define READ_GRAMMAR_H_INCLUDED

typedef std::vector<std::string> Rule;
typedef std::vector<Rule> Rule_collection;
typedef std::map<std::string, Rule_collection> Grammar;

Grammar read_grammar(std::istream& in);

#endif // READ_GRAMMAR_H_INCLUDED

This is giving me the error error: 'map' in namespace 'std' does not name a type

If I change the third typedef to typedef std::vector<Rule_collection> Grammar; (not that I want this, just for example) it builds with no errors.

Any idea what the problem is? I have no idea whether I'm doing something trivial the wrong way, or whether the whole approach is incorrect

Aucun commentaire:

Enregistrer un commentaire