c++ - 为什么 CLion 不将类标记为类?

标签 c++ class clion

enter image description here enter image description here当我尝试编写此类时,它不会将其视为类,并且无法解析类 Card。我能用它做什么?

#ifndef HAND_HPP
#define HAND_HPP

#include <iosfwd>
#include <vector>
#include "cards.hpp"

class Hand {  //it doesn't mark it as class
private:
    int maxSize;
    std::vector<Card> hand;  //Cannot resolve variable 'Card'

public:
 ***
};


#endif //HAND_HPP

现在我可以上传图片了,所以看起来就像这样。 并且cards.hpp(其中声明了Card)包含hand.hpp。

最佳答案

您需要#include包含类 Card 声明的头文件,或者声明Card以上类Hand 。编译器需要知道 Card 的完整定义(而不是实现)类,因此任何前向声明都不会安抚编译器。

关于c++ - 为什么 CLion 不将类标记为类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26679804/

相关文章:

c++ - CLion 禁用 C++98 模式以支持 C++11

c++ - 为什么我们应该在全局函数/对象上使用 "::"运算符?

c++ - 我应该在主函数内部还是外部声明一个变量?

c++ - 使用 char 或 unsigned char 数组存储原始数据更好吗?

python - 在 Python 3 中计算列表的平均值

c# - 如何命名使用属性的类?

C++ 帐户创建程序崩溃

javascript - jQuery - 获取元素的类

c++ - CLion 中的 allegro5 项目,ld : library not found error

c++ - 克里昂集成开发环境 : Use ssh as an environnent toolchains instead of MinGW/Cygwin on Windows