我有一个模板类,它需要从其模板参数中获取嵌套类型。它在其成员函数签名中使用这些类型。我发现了以下解决方案来声明成员函数:如何使用模板参数的嵌套类型在类别外的签名中定义模板类函数
template <class ElementType>
class AKL_API AklMemoryPool
{
public:
typedef typename ElementType::DataType DataType;
typedef typename ElementType::RetrieveType RetrieveType;
...
RetrieveType Retrieve(unsigned int offset) const;
DataType* EstablishCUDA();
DataType* WriteToCUDA();
DataType* ReadFromCUDA();
DataType* GetCUDA();
...
};
但我可以只在类声明中定义函数。 如果我试图把它定义外,如:
template <class ElementType>
AklMemoryPool<ElementType>::RetrieveType AklMemoryPool<ElementType>::Retrieve(unsigned int offset) const
{
...
}
我得到的编译错误。
这里是问题,因为我需要隐藏实现,因为它会产生编译错误,如果从某些地方可见的话。我仅将AklMemoryPool类用作基类,因此我决定将实现移至cpp文件并将其包含在继承类的cpp文件中。
所以这里是一个问题: 如何在类之外定义这些函数?
我忘了C++ 11的东西:d +1 –
谢谢! C++ 11版本完美的作品。有时间阅读有关C++ 11的更多信息... – Hvarnah