如何在不同模板类的模板类中使用嵌套模板类
How to use a nested template class within a template class from a different template class
本文关键字:嵌套 更新时间:2023-10-16
首先,我希望问题标题有一定的意义。
我有以下类结构:
class A : public Singleton<A>
{
public:
template <typename T> class Buffer
{
public:
//ctor & dtor
T* get() { return ptr; }
private:
T* ptr;
};
// class A stuff
};
这个类应该作为模板参数传递给处理程序类,并在类的模板函数中使用:
template <class MODEL> class Handler
{
public:
// ctor & dtor
template <typename T> typename MODEL::Buffer<T>* create(...) // error c2988
{ // create a buffer }
};
然而,编译器无法确定正确的类型名,并引发错误C2988:无法识别的模板声明/定义(vc++2012年11月VS 2012中的CTP编译器)。我找不到任何解决方案来告诉编译器如何处理内部类模板。所以问题是:如何让它发挥作用?
如有任何帮助,我们将不胜感激。
您需要帮助编译器消除歧义,并告诉它Buffer
是什么:
template <typename T> typename MODEL::template Buffer<T>* create(...);
// ^^^^^^^^
请参阅此问答;A了解更多信息。
相关文章:
- 嵌套在类中时无法设置成员数据
- 无法访问嵌套类.类的使用无效
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 如何在C++中初始化嵌套类中的2个memeber
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 在C++中搜索嵌套多映射值
- 在C++中将矢量转换为嵌套地图
- C++嵌套if语句,基本货币交换
- 在nlohmann json中,如何将嵌套对象的数组转换为嵌套结构的向量
- 嵌套的匿名命名空间
- 了解嵌套循环打印星号图案
- 如何使用boost::具有嵌套结构和最小代码更改的序列化
- 嵌套for循环C++的问题(初学者)
- 从嵌套在std::映射中的std::列表中删除元素的最佳方式
- 用C#中的并集模拟C++嵌套结构
- 部分专业化和嵌套模板
- 嵌套While循环不起作用(C++问题)
- C++-模板嵌套类的引用初始化无效
- 如何在嵌套类中正确使用友元声明?
- UE4 C++ 我无法将 JSON 嵌套值获取到 TArray