我有两个模板类:外部和内部。我正在从其他内部类对象进行类型转换到内部类。我收到编译错误。如何解决这个问题?
template<typename O>
struct outer
{
template<typename I>
struct inner
{
};
inner<int> *ptr;
outer();
};
template<typename O,typename I>
void callme()
{
reinterpret_cast< outer<O>::inner<I> *>(NULL);
}
最佳答案
你想要:
reinterpret_cast<typename outer<O>::template inner<I> *>(nullptr);
// ^^^^^^^^ ^^^^^^^^ ^^^^^^^
名称 outer
和 inner
是从属名称(它们依赖于模板参数),因此您需要显式指定它们的“种类”(值、类型、模板) )。
关于c++ - 如何对内部模板类使用重新解释强制转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43763109/