在包含该类列表的结构后定义的C ++类[重复]

问题描述 投票:1回答:1

这个问题在这里已有答案:

我有一个父虚拟类(及其子类,但这些不是问题)

//---------------------------------------------------------------------
class TPowerComponent
{
public :
    int X, Y, Rotation;
    __fastcall TPowerComponent( PowSymbType AType );
    __fastcall TPowerComponent( TStream& S );
    virtual void __fastcall Store( TStream& S );
    __fastcall ~TPowerComponent();
    virtual void __fastcall Paint(TCanvas * Canvas, const WorkSheetInfoRec& WSInfo);        // se dessine
};

其中一个方法(paint)使用WorkSheetInfoRec结构,该结构由上面定义:

struct WorkSheetInfoRec {
    int WSOpt, Study;
    std::list<TPowerComponent*> NetWorkList;
};

问题是这个结构使用了一个父类的objectz列表,它有一个方法(paint),它也引用了一个使用该列表的结构......所以编译失败,因为每个必须在另一个之前声明..如何在头文件中处理它。

谢谢

c++ list class declaration
1个回答
8
投票

使用前瞻声明:

class TPowerComponent;
struct WorkSheetInfoRec {
    int WSOpt, Study;
    std::list<TPowerComponent*> NetWorkList;
};
© www.soinside.com 2019 - 2024. All rights reserved.