小编Mar*_*aró的帖子

是否可以隐藏模板类的实现?

我有一个依赖于"Blibrary"的图书馆"myLibrary".我希望"myLibrary"的用户不知道这种依赖.我试图隐瞒它没有运气,这是我现在所拥有的一个例子.

#include <game/Object.h>
#include <Blibrary/Component.hpp>   // How can I remove this library header?
                                    // forward declaring it? it's a template..

namespace myLibrary {

    template<typename T>
    struct Component: public Object, public Blibrary::Component<T>
    {
    };


    //template<typename T>
    //class Blibrary::Component<T>;    //I Tried something like that..

    //template<typename T>
    //struct Component: public Object
    //{
    //  Blibrary::Component<T> * m_impl;
    //};
}



//I want the user do this when declaring a usermade component:

#include <game/Component.h>   //<-- but without the Blibrary include dependency


class Position: public myLibrary::Component<Position>
{ …
Run Code Online (Sandbox Code Playgroud)

c++ templates

3
推荐指数
1
解决办法
1482
查看次数

标签 统计

c++ ×1

templates ×1