Domanda

I currently have the following two classes

class TOrder 
{
public:

private:
    .......
};  

Now my other class is :

#include "TOrder.h"

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

    }       
}

The above works fine the problem starts when I use an object of OrderDis in TOrder as such

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

    .......
};

Any suggestion on how I could use forward declaration to resolve my issue ?

È stato utile?

Soluzione

You could forward OrderDispatcher in TimeOrder.h

namespaceA
{
    namespaceB
    {
        class OrderDispatcher;
    }
}

class TimedOrder 
{
//...
};

Altri suggerimenti

The forward declaration can be written as:

namespace A{ namespace B{ class OrderDispatcher; } }

As you only use a pointer to TimedOrder in the OrderDispatcher class, it can be solved by simply not including TimedOrder.h in the OrderDispatch.h file. Instead just declare the TimedOrder class:

class TimedOrder;

No need to muck about with namespaces and such then.

Note: You can't declare it in any of the namespaces, declare it instead where you now do your #include.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top