Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
dllexport避免头文件中的模板实例 我有一个C++类,它编译好,直到我尝试从DLL导出它。< /P>_C++_Templates_Dllexport - Fatal编程技术网

dllexport避免头文件中的模板实例 我有一个C++类,它编译好,直到我尝试从DLL导出它。< /P>

dllexport避免头文件中的模板实例 我有一个C++类,它编译好,直到我尝试从DLL导出它。< /P>,c++,templates,dllexport,C++,Templates,Dllexport,MyClass.h: class SomeClassNotDefinedHere; class MyClass { protected: templated<SomeClassNotDefinedHere> m_member; } 它无法编译,试图实例化模板化的的所有内联成员 有没有一个简单的方法来避免这种情况?我不想将这里没有定义的类添加为使用MyClass的每个库的依赖项 一些模板化的代码,这是一个类似于智能指针的类。(尽量减少我的示例,真正的模板化类是

MyClass.h:

class SomeClassNotDefinedHere;

class MyClass {
   protected:
   templated<SomeClassNotDefinedHere> m_member;     
}
它无法编译,试图实例化模板化的
的所有内联成员

有没有一个简单的方法来避免这种情况?我不想将这里没有定义的类添加为使用MyClass的每个库的依赖项

一些模板化的代码,这是一个类似于智能指针的类。(尽量减少我的示例,真正的模板化类是)

模板
类模板化
{
公众:
类型定义T元素_类型;
模板化():ptr(0){}
模板化(T*ptr):_ptr(ptr){if(_ptr)_ptr->ref()}
模板化(const templated&rp):_ptr(rp._ptr){if(_ptr)_ptr->ref()}
私人:
T*_ptr;
}

避免类或大型重新设计是我希望避免的事情,代码已经在linux上使用。

什么是模板化的
?另一节课?它的定义是什么?它看起来像什么?请发布可编译的代码。
\uuu declspec(dllexport)
在类上开始是一个非常糟糕的主意。我建议制作一个与C兼容的API,它接受对象指针作为参数(就像Win32 API一样),这样更健壮。@Praetorian添加了一些代码和指向完整类的链接。@BenVoigt因为这些类已经在使用中,所以我希望避免更大的更改。(这是我在将库从linux移植到windows时遇到的第一个真正的问题)
 class __declspec(dllexport) MyClass
template<class T>
 class templated
{
    public:
        typedef T element_type;

        templated() : _ptr(0) {}
        templated(T* ptr) : _ptr(ptr) { if (_ptr) _ptr->ref(); }
        templated(const templated& rp) : _ptr(rp._ptr) { if (_ptr) _ptr->ref(); }
       private:
            T* _ptr;
}