C++模板内部类中的 decltype
C++ decltype in template inner class
我的问题由以下示例说明:
#include <vector>
template <class T>
class TestNest{
public:
std::vector<T> m_list;
class InsideNest{
const TestNest<T>* m_test;
decltype(m_test->m_list.begin()) m_iter;
public:
InsideNest(const TestNest<T>* source)
:m_test(source)
,m_iter(source->m_list.begin())
{}
};
};
int main(int argc, char *argv[])
{
TestNest<int> outside;
TestNest<int>::InsideNest inside(&outside);
}
不编译的部分(至少不是MSVC2013(是decltype(m_test->m_list.begin())
.知道我该如何解决这个问题吗?
编辑:更改了代码以显示main((和 #include
关闭问题。这是MSVC2013的缺点。它将在"计算"完整类型的成员之前解决decltype()
,因此在 decltype 中,对方法的任何访问都是编译器错误。即使使用全局模板函数(例如 decltype(std::begin(m_list))
( 将不起作用。其他更现代的编译器工作。
相关文章:
- 在设计 SDK 时,我是否应该在 C++ 头文件中完全隐藏内部类?
- 如何声明由多个线程调用的 C++ DLL 的内部类,而无需导出类
- 从内部类继承
- 如何将枚举类转发声明为模板化类的内部类?
- 从内部类中的方法从包含类调用方法
- 从模板化父类中的派生内部类访问受保护的成员变量
- C++模板类的内部类访问
- 使用类模板的内部类模板专用化模板
- 如何使用包含内部类的类实例有效地从内部类访问成员?
- C++ 如何在外部类中声明的内部类中使用变量
- 在C++中将内部类实现为具有名称空间的独立类有什么好处
- 参数化类的别名(或类型定义)内部类
- 从内部类的析构函数调用虚拟函数
- 如何在没有setter的情况下设置类内部类的成员变量?
- 具有相同名称的方法和内部类(错误:.. 与前面的声明冲突)
- 内部类私有成员访问和封闭的友好性
- 在C++中从内部类对象获取外部类对象
- 在它所属的模板类中使用内部类
- C++命名空间、内部类和运算符解析
- C++模板内部类中的 decltype