Hi,
I've been struggling quite a while to get 2 classes of different namespace in different header files, knowing each other. The only way I managed to solve this is having a forward declaration right before including the header of the other. I've pasted the code below. While doing this I have a few questions, I hope someone can clarify this;
1. When classes A and B (of different namespaces) need to know each other, why doesn't it work to forward declare them both ways around?
(even though they're only needed as a pointer or const ref)
2. Why does my forward declaration of CD3dscene work without 'being' in the d3drenderer namespace and the renderqueue fwd declaration doesn't work, unless I explicitly place it there, i.e. namespace Crealysm_renderer { class CRenderQueue; }. Fwd declaring "Crealysm_renderer::CRenderQueue' gives an error the Crealysm_renderer is not a known namespace.
Any ideas?
// d3dscene header
#ifndef CD3DSCENE_H
#define CD3DSCENE_H
class Crealysm_d3drenderer::CD3dscene;
#include "Crealysm_renderqueue.h"
namespace Crealysm_d3drenderer
{
class CD3dscene
{
// etc
// this only works if the fwd declaration is 'within' the Crealysm_renderer namespace
// bool TransformObjects(const Crealysm_renderer::CRenderQueue &pQueue);
bool TransformObjects(const CRenderQueue &pQueue);
};
}
#endif
// renderqueue header
#ifndef CRENDERQUEUE_H
#define CRENDERQUEUE_H
class CRenderQueue;
#include "Crealysm_d3dscene.h"
namespace Crealysm_renderer
{
class CRenderQueue
{
// etc.
bool Create(const Crealysm_d3drenderer::CD3dscene *pD3dscene, const int pLightingEffectId); // changed
};
}
#endif