C++ 在'之前应为类名;{';标记,则在预声明时无效地使用不完整的类型';类名称'

C++ 在'之前应为类名;{';标记,则在预声明时无效地使用不完整的类型';类名称',c++,inheritance,C++,Inheritance,我试图在基于SFML的对象中添加继承,但我无法解决出现错误的问题 *expected class-name before '{' token* 当我试图通过预先声明父类来解决这个问题时,我被阻止了 *invalid use of incomplete type 'class Object'* 我用Object作为父类创建了矩形和圆形类 Object.hpp #如果包含NDEF对象(水电站) #定义包含的对象\u水电站\u #包括“./MainClass.hpp” #包括“./Data/D

我试图在基于SFML的对象中添加继承,但我无法解决出现错误的问题

*expected class-name before '{' token* 
当我试图通过预先声明父类来解决这个问题时,我被阻止了

*invalid use of incomplete type 'class Object'* 
我用Object作为父类创建了矩形和圆形类

Object.hpp

#如果包含NDEF对象(水电站)
#定义包含的对象\u水电站\u
#包括“./MainClass.hpp”
#包括“./Data/Data.hpp”
#包括
#包括
类对象
{
公众:
对象();
虚拟对象();
虚拟void update()=0;
虚空绘制()=0;
};
#endif//OBJECTPARENT\u水电站\u包括在内
在Object.cpp文件中,我只有构造函数和解构器的定义

矩形.hpp

#如果包含矩形水电站#
#定义包含的矩形\u HPP\u
#包括“Object.hpp”
#包括
#包括“./Data/Data.hpp”
#包括“./MainClass.hpp”
#包括
#包括
类对象;//只需在Circle.hpp和Rectangle.hpp中插入“#include”Object.hpp”,以及使用对象类的任何其他类似文件:

#include "ObjectParent.hpp"
#include <SFML/Graphics.hpp>
#include "../Data/Data.hpp"
#include "../MainClass.hpp"
#include "Object.hpp"           //    <----------
#include <iostream>
#include <cstdlib>
#包括“ObjectParent.hpp”
#包括
#包括“./Data/Data.hpp”
#包括“./MainClass.hpp”

包含“Obj.HPP”//而不是前向声明,你是否曾尝试过“代码> >包含“Obj.HPP”< /C>在所有需要的文件中?在C++中,所有符号在使用之前都必须声明,否则编译器不知道它们存在和可能。“我试图改变所有包含的顺序,删除内容并添加内容"通过尝试和错误编程C++通常不太好。你必须学习语言,知道编写代码时你在做什么。实验/猜测通常是无效的,语言复杂而复杂,就像C++一样。
数据.hpp
包括此处显示的任何标题(
矩形.hpp
圆形.hpp
,或
对象.hpp
)?编译哪个文件的编译器出现此错误?Rectangle.hpp和Circle.hppdo不直接编译这些文件。这些文件是头文件。请编译相应的源文件。我的意思是“Rectangle.cpp”和“Circle.cpp”。如果我理解正确,我是否必须单独编译这些文件,而不编译整个程序?当我编译矩形.CPP,我从CURLC.HPP中得到错误,Circle.cpp在矩形中得到错误。HPPNO。当编译一个由一些源文件(.CPP)和一些头文件(.HPP)组成的C++程序时,只需要将源文件发送到编译器作为输入。例如,如果您的项目有三个文件:[main.cpp、object.cpp和object.hpp]、main.cpp和object.cpp是编译器输入:“g++-o app main.cpp object.cpp”
#ifndef RECTANGLE_HPP_INCLUDED
#define RECTANGLE_HPP_INCLUDED

#include "Object.hpp"
#include <SFML/Graphics.hpp>
#include "../Data/Data.hpp"
#include "../MainClass.hpp"

#include <iostream>
#include <cstdlib>

class Object; // <--- without this line *expected class-name before '{' token*, but with it *invalid use of incomplete type 'class Object'* 


class Rectangle : public Object
{
public:

    Rectangle(/*args*/);
    virtual ~Rectangle();

    //some functions

    void update();
    void draw();

private:
    
    //some members

};

#endif // RECTANGLE_HPP_INCLUDED
#ifndef CIRCLE_HPP_INCLUDED
#define CIRCLE_HPP_INCLUDED

#include "Object.hpp"
#include <SFML/Graphics.hpp>
#include "../Data/Data.hpp"
#include "../MainClass.hpp"

#include <iostream>
#include <cstdlib>

class Object; // <--- without this line *expected class-name before '{' token*, but with it *invalid use of incomplete type 'class Object'* 


class Circle: public Object
{
public:

    Circle(/*args*/);
    virtual ~Circle();

    //some functions

    void update();
    void draw();

private:
    
    //some members

};

#endif // CIRCLE_HPP_INCLUDED
#include "ObjectParent.hpp"
#include <SFML/Graphics.hpp>
#include "../Data/Data.hpp"
#include "../MainClass.hpp"
#include "Object.hpp"           //    <----------
#include <iostream>
#include <cstdlib>