C++ 错误 : Class has-a-relationship with Struct in Same Header File

标签 c++ eclipse compiler-errors

我正在定义一个 C++ 头文件,由于某种原因,当我尝试引用在同一个文件中定义的结构以及我创建的枚举类时,我正在创建的类会出错。

虽然我对 Java 和 C# 有一些经验,但我对 C++ 还是个新手。即便如此,我的编程经验还是比较低的。我初始化引用错误吗?我应该将结构和枚举都放在单独的头文件中吗?

#include <iostream>
#include <stdio.h>

class Character 
{
private:

    Stats stats; //<--error: "Type 'Stats' could not be resolved."

public:




};

struct Stats
{
    int strength;
    int intelligence;
    int endurance;
    int speed;
    int agility;
    int luck;
};

enum Race 
{
    NONE,
    HUMAN,
    ALIEN,
    ANDROID
};

注意:我使用的是用于 C++ 的 Eclipse 3.7 (Indigo),以防万一。

最佳答案

C++从文件的顶部到底部进行解析;您需要将 Stats 类定义移动到 Character 类定义之上。

关于C++ 错误 : Class has-a-relationship with Struct in Same Header File,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6448830/

相关文章:

c++ - 计算平方根的程序c++

java - Eclipse Java代码格式

r - R中仅Unix的软件包错误

使用 -D 选项时 gcc 编译器错误

android - arm-linux-androideabi-ar : Command not found in NDK

c++ - MATLAB BWLABEL 的 OpenCV 替代品

c++ - 是否有可能 'member function pointer' 指向同一类中的成员函数

java - 将Android项目导入Eclipse后,Package Icons为 "white"

java - RCP 3.x 可编辑 PropertySheet View

c++ - 使用 System() 的随机参数?