Friend classes across different namespaces. Is that possible

有些话、适合烂在心里 提交于 2019-11-30 11:04:19

See if something like this works a bit better (for the moment, I've merged them into a single source file).

#include <string>

namespace tools {
    namespace sysInput {
        class CGeometryManager3D;
    }
}

namespace render {   
    class CMesh3D
    {
    public:
        friend class tools::sysInput::CGeometryManager3D;
        CMesh3D(void);
        ~CMesh3D(void);
    };    
}

namespace tools {
    namespace sysInput{
        class CGeometryManager3D
        {
        public:
            bool loadFromFile(render::CMesh3D& mesh, std::string filename);
            CGeometryManager3D(void);
            ~CGeometryManager3D(void);
        };

    };    
}

I guess you need to remove following code in the second file:

#include "GeometryManager.h"

class CGeometryManager3D;

The first line causes circular inclusion as the comments in the question suggests;

The second line declares a totally irrelevant class as it is in the global name space;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!