C++初学者 - 在类中使用类时遇到麻烦

F. *_* P. 0 c++ class return-type header-files

我正在做一个大学项目,我必须在那里实施一个简单的Scrabble游戏.

我有一个player班级(包含分数和玩家的手,形式为a std::stringscore类(包含名称和数字(int)分数).

其中一个Player成员函数是Score getScore(),返回该玩家的Score对象.但是,我在编译时遇到以下错误:

player.h(27) : error C2146: syntax error : missing ';' before identifier 'getScore'
player.h(27) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
player.h(27) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
player.h(27) : warning C4183: 'getScore': missing return type; assumed to be a member function returning 'int'
player.h(35) : error C2146: syntax error : missing ';' before identifier '_score'
player.h(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
player.h(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Run Code Online (Sandbox Code Playgroud)

这是第27和35行:

Score getScore(); //defined as public
(...)
Score _score; //defined as private
Run Code Online (Sandbox Code Playgroud)

我知道编译器无法识别Score为有效类型......但为什么呢?我Score.h在开头时正确地包含了player.h:

#include "Score.h"
#include "Deck.h"
#include <string>
Run Code Online (Sandbox Code Playgroud)

我有一个默认构造函数用于Score定义Score.h:

Score(); //score.h

//score.cpp
Score::Score()
{
    _name = "";
    _points = 0;
}
Run Code Online (Sandbox Code Playgroud)

任何输入将不胜感激!

谢谢你的时间,

弗朗西斯科

编辑:

根据要求,score.h和player.h:http ://pastebin.com/3JzXP36i http://pastebin.com/y7sGVZ4A

Joe*_*oeG 7

你有一个循环包含问题 - 在这种情况下相对容易修复.

取出#include "Player.h"Score.h.


请参阅问题,以获得有关Score实际使用时需要执行的操作的说明和讨论Player.


至于你得到的编译器错误,这就是微软编译器报告未定义类型的使用方式 - 你应该学会将它们全部精神上翻译成"未定义的声明中使用的类型".