我正在尝试编译以下程序,该程序使用名为Noun的枚举类。它从字符串中获取输入并使用映射枚举数据。
以下是定义枚举类的头文件:
nouns.h
#ifndef NOUNS_H
#define NOUNS_H
#include <iostream>
#include <map> //std::map
#include <string> //std::string
#include "classes.h" // where classes are stored
#include "functions.h" // standard functions kept here
#include "cmdtree.h" // where the arguments from these functions are sent
enum class Noun
{
name,
/* other nouns */
invalid
};
std::map < std::string, Noun > knownNouns =
{
{ "name", Noun::name },
/* more stuff in the map */
{ "suspect", Noun::suspect }
};
Noun parseNoun(std::string &noun)
{
auto n = knownNouns.find(noun);
if ( n == knownNouns.end() ) {
return Noun::invalid;
}
return n->second;
}
void ask (Noun noun);
void look (Noun noun);
#endif /* NOUNS_H */
编译时,我遇到了一些错误:
In file included from functions.h:16:0,
from classes.h:15,
from nouns.h:37,
from nouns.cpp:1:
verbs.h:44:15: error: 'Noun' was not declared in this scope
int verbProc (Noun noun, Verb verb);
^
verbs.h:44:31: error: expected primary-expression before 'verb'
int verbProc (Noun noun, Verb verb);
^
verbs.h:44:35: error: expression list treated as compound expression in initializer [-fpermissive]
int verbProc (Noun noun, Verb verb);
^
In file included from classes.h:15:0,
from nouns.h:37,
from nouns.cpp:1:
functions.h:23:32: error: 'Noun' has not been declared
char validateInput (Verb verb, Noun noun);
^
在verbs.h中,它告诉我“名词”未在范围内声明,我查看我的头文件......
verbs.h:
#ifndef VERBS_H
#define VERBS_H
#include <iostream>
#include <map>
#include <string>
#include "nouns.h"
#include "classes.h"
#include "functions.h"
/*
* See the nouns.h header for better documentation on what exactly this
* is doing.
*/
enum class Verb
{
ask, // first verb
/* other verbs */
invalid // last verb
};
std::map < std::string, Verb > knownVerbs =
{
{ "ask", Verb::ask },
/* other stuff in map */
{ "examine", Verb::look }
};
Verb parseVerb(const std::string &verb);
int verbProc (Noun noun, Verb verb); // <-- function where Noun is "undeclared."
#endif /* VERBS_H */
类似的非延迟错误发生在“functions.h”中:
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <iostream>
#include <string>
#include <cstring>
#include "classes.h"
#include "verbs.h"
#include "nouns.h"
#include "classes.h"
#include "cmdtree.h"
void localPause ();
void readInput (char* &command, const int MAXL, std::string &noun, std::string &verb);
char verifyExit(char exitChoice);
char validateInput (Verb verb, Noun noun); // <-- error here, "Noun has not been declared"
void initializeSuspect();
void introduction();
#endif /* FUNCTIONS_H */
有人能发现我不能发现的东西吗?