如何确定作为对象传递给另一个类的模板类的数据类型
how to determine the data type of a template class passed as object to another class
这是我的代码。我如何使A::type
成为int
或double
或其他用于创建B
类实例的东西?
template<class X>
class A
{
typedef "*****" type
........
.....
......
}
template<class Y>
class B
{
......
.......
....
}
int main()
{
B<int> x;
A<B<int> > y;
.....
....
....
}
可以了
template<class X>
class A
{
typedef typename X::type type;
};
template<class Y>
class B
{
public:
typedef Y type;
};
也许像这样:
template <typename T>
struct B
{
typedef T type;
// ...
};
template <typename> struct A { /* ... */ };
typedef B<int> MyB;
int main()
{
MyB x;
A<MyB::type> y;
}
也许这会有帮助。
template <class T>
class B;
template <class T>
class A {
public:
typedef T type;
};
template <class T>
class A<B<T>> : public A<T> {};
template <class T> class B {};
int main()
{
A<B<int>>::type x;
}
相关文章:
- 在 C++ 中将一个模板类型的对象类型转换为另一个模板类型
- c ++ 我是否需要手动删除指向另一个具体类型的 void* 指针?
- 使用 SFINAE 测试是否可以将一个指针类型static_cast到另一个指针类型
- 检查数值类型是否是另一个数值类型的子集
- 为什么直接传递"this"指针来存档是一个错误,而另一个相同类型的指针是可以的?
- 将 std::variant 转换为另一个具有类型子集的 std::variant
- 参考数据会在const函数中更改另一个数据成员
- 让 pthread 等待另一个数据
- 如何通过友元函数将一个对象(类型a)传递给另一个对象(类型b)的私有对象(类型a)
- 在c++中的另一个相同类型的接口中克隆一个接口
- 在构造函数中为另一个相同类型的对象构造对象是个好主意吗
- c++声明一个数据类型的字节数组,该数组存储在字符串中
- 从一个结构复制到另一个不同类型的结构
- 如何将结构拆分为块,以便将字节保存到 C/C++ 中的另一个数据结构
- 在具有C++中另一个类类型的类中声明属性
- WriteFile函数如何与磁盘上的另一个数据交互
- C++中的另一个双重类型技巧
- 将一个对象数据复制到另一个相同类型 C++ 的对象
- c++声明另一个类类型的数组
- 基于另一个数据成员的类数据成员类型