这可能只是一个我没有看到的简单错误,但我认为我只是做错了什么。别担心,我没有在我的标头函数中使用命名空间 std 或任何似乎是这个人的问题的东西 [我读到的问题与我的类似][1] [1]:为什么我得到字符串没有命名类型错误?
我现在收到 4 个错误:
C:\Documents and Settings\Me\My Documents\C++Projects\C++\RandomSentence\Nouns.h|8|错误:命名空间“std”中的“字符串”未命名类型|
C:\Documents and Settings\Me\My Documents\C++Projects\C++\RandomSentence\Nouns.h|12|错误:命名空间“std”中的“字符串”未命名类型|
C:\Documents and Settings\Me\My Documents\C++Projects\C++\RandomSentence\Nouns.h|13|错误:命名空间“std”中的“字符串”未命名类型|
C:\Documents and Settings\Me\My Documents\C++Projects\C++\RandomSentence\Nouns.cpp|9|error: no 'std::string Nouns::nounGenerator()' member function声明在类'Nouns' |
||=== 构建完成:4 个错误,0 个警告 ===|
这是我的头文件:
class Nouns
{
public:
Nouns();
std::string noun;
protected:
private:
int rnp; // random noun picker
std::string dog, cat, rat, coat, toilet, lizard, mime, clown, barbie, pig, lamp, chair, hanger, pancake, biscut, ferret, blanket, tree, door, radio;
std::string nounGenerator()
};
这是我的 cpp 文件:
#include "Nouns.h"
#include <iostream>
Nouns::Nouns()
{
}
std::string Nouns::nounGenerator(){
RollRandom rollRandObj;
rnp = rollRandObj.randNum;
switch(rnp){
case 1:
noun = "dog";
break;
case 2:
noun = "cat";
break;
case 3:
noun = "rat";
break;
case 4:
noun = "coat";
break;
case 5:
noun = "toilet";
break;
case 6:
noun = "lizard";
break;
case 7:
noun = "mime";
break;
case 8:
noun = "clown";
break;
case 9:
noun = "barbie";
break;
case 10:
noun = "pig";
break;
case 11:
noun = "lamp";
break;
case 12:
noun = "chair";
break;
case 13:
noun = "hanger";
break;
case 14:
noun = "pancake";
break;
case 15:
noun = "biscut";
break;
case 16:
noun = "ferret";
break;
case 17:
noun = "blanket";
break;
case 18:
noun = "tree";
break;
case 19:
noun = "door";
break;
case 20:
noun = "radio";
break;
}
return noun;
}