如何在 typedef 中使用模板化类的数据成员
How to use data member of templatized class in typedef
template <class T>
struct A {
typedef B type;
}
template<>
struct A<double>
{
typedef double type;
};
template<typename T, typename U>
B<U> func()
{
A<U>::type my_type;
my_type tmp;
}
此代码不使用 g++ 编译器进行编译。 错误消息是:
错误:模板参数列表太少
有人可以解释一下。
谢谢和问候,范萨尔
首先,对有问题的错误表示歉意。 正确的问题应该是:
template <class T>
struct A {
typedef B type;
}
template<>
struct A<double>
{
typedef double type;
};
template<typename T, typename U>
void func()
{
typedef A<U>::type my_type;
my_type tmp;
}
这里基本上的问题是编译器对语句感到困惑
typedef A<U>::type my_type;
无论是类的数据成员还是类型。 所以我们必须明确地说它是一种类型。所以用下面的语句替换上面的语句
typdedef typename A<U>::type my_type;
相关文章:
- 用于访问容器<T>数据成员的正确 API
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 数据成员SFINAE的C++17测试:gcc vs clang
- 派生类是否可以在抽象工厂设计模式中具有数据成员
- 如何在c++中定义以struct为数据成员的类中的构造函数
- 静态数据成员模板专用化的实例化点在哪里
- int数据类型的指针指向的是什么,如果是一个类的私有数据成员,我们创建了该类的两个对象?
- 使用指针访问数组中的对象数据成员
- 友元函数无法访问私有数据成员 (c++)
- 我可以在 C++ 中将数据成员/变量从其定义之外添加到结构中吗?
- 为什么将一个结构的引用设置为等于另一个结构只会更改一个数据成员?
- 将私有数据成员添加到野牛生成的类中
- 输入数据成员未按要求工作
- 二维矢量数据成员
- 在类 A 中创建类型为 B 类的向量 - 访问数据 [C++] [成员在两个类中都是私有的]
- 调用在 HXX 文件中声明的静态数据成员
- 是否可以根据其数据成员的类型确定类型的大小
- 访问数据成员(本身是对象)的数据成员,就好像它们是类成员一样
- 使公共数据成员在C++中无法访问
- 如何在 typedef 中使用模板化类的数据成员