【发布时间】:2011-09-03 02:34:10
【问题描述】:
我怀疑我不能直接使用 PIMPL 模式执行此操作。是否可以有一个指向模板类的智能指针?我无法通过转动shared_ptr 声明的旋钮进行编译。
// ============Foo.h ============
// Forward declare the implementation
template <typename T> class FooImpl;
class Foo
{
public:
Foo getInstance(const string& fooType);
...
private:
shared_ptr< FooImpl<T> > m_impl;
};
// ============FooImpl.h ============
template <typename T>
class FooImpl
{
...
};
在 Visual Studio 2008 下:“错误 C2065:'T':未声明的标识符”。我在 GCC 下收到类似的错误。 如果我取消对 FooImpl 的参数化(以便 FooTempl 继承自 FooImpl),代码将编译。
我怀疑我无法参数化智能指针,但我可能错了。
编辑:second Visual Studio 错误更能说明问题:“错误 C3203: 'FooImpl' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a实型”
杰夫
【问题讨论】:
-
T在shared_ptr<FooImpl<T>> m_impl;声明中是什么类型?Foo应该是接受T的模板吗? -
@silico: T 将是 Crypto++ 对象,例如 MD5、SHA1、SHA256 等哈希值。
-
您遇到什么错误? 总是发布编译器错误。
标签: c++ templates smart-pointers