c++ - 以下场景如何使用前向声明

标签 c++ forward-declaration

我目前有以下两个类

class TOrder 
{
public:

private:
    .......
};  

现在我的另一门课是:

#include "TOrder.h"

namespace namespaceA
{
    namespace namespaceB
    {
        class OrderDis
        {
        private:
            TOrder* frmPointer;
                    .....
        };

    }       
}

当我在 TOrder 中使用 OrderDis 的对象时,上面的工作正常问题就开始了

#include <QMainWindow>
#include "OrderDis"  //Added - Creates Problem
class TimedOrder 
{
public:

    .......
};

关于如何使用前向声明来解决我的问题有什么建议吗?

最佳答案

您可以在 TimeOrder.h 中转发 OrderDispatcher

namespaceA
{
    namespaceB
    {
        class OrderDispatcher;
    }
}

class TimedOrder 
{
//...
};

关于c++ - 以下场景如何使用前向声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19019007/

相关文章:

c++ - 为什么 srand(time(NULL)) 即使我反复重置它也能顺利工作?

c++ - C/C++ 编译器如何在头文件中找到原型(prototype)的定义?

c++ - 类前向声明​​ C++

c++ - 错误 : Invalid use of incomplete type struct Subject; error: forward declaration of struct Subject

c++ - 关于右值引用的一些说明

c++ - 如何限制 typedef 类型的隐式转换?

.net - 前向声明问题

c - 什么是参数前向声明?

c++ - RSA_Private_Decrypt 随机失败

c++ - C可以有对象吗?