MSVC:无法识别的模板声明/定义(使用 Clang/GCC 编译)
MSVC: unrecognizable template declaration/definition (compiles with Clang/GCC)
我尝试构建一个在OSX(clang)和Linux(GCC/Clang)上编译良好的库。我偶然发现了MSVC/Visual Studio 2017不理解的模板定义。我可以把它归结为:
#include "stdafx.h"
template<class T>
class Parent {
class Child {
friend class Parent;
public:
Child(const Child &r);
};
};
template<class T>
Parent<T>::Child::Child(const Parent<T>::Child &r) {
*this = r;
}
int main(int argc, char const *argv[]) {
/* code */
return 0;
}
这(仍然)会导致以下错误:
1>...consoleapplication1.cpp(13): error C2988: unrecognizable template declaration/definition
1>...consoleapplication1.cpp(13): error C2059: syntax error: '('
1>...consoleapplication1.cpp(13): error C2143: syntax error: missing ';' before '{'
1>...consoleapplication1.cpp(13): error C2447: '{': missing function header (old-style formal list?)
但(仍然)使用 Clang 或 GCC 在 OSX 上编译。 stdafx.h
和main
不是实际库代码的一部分,但已添加以允许在VS Windows命令行项目中使用它。
我在这里错过了什么?MSVC 在模板中的成员类或友元声明方面是否存在问题?
VC++的问题是参数类型没有被typename
限定。[温度]/7:
[...]的定义之内 声明符 ID(关键字)后面的类模板的成员 引用以前的名称时不需要
typename
声明类型或类的类模板的声明成员 模板。
声明符 id 是声明的第一个组件,因此参数子句中的任何成员类型都不需要以 typename
为前缀。
相关文章:
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 使用用户定义函数的字符串反转
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- 使用命名空间时出现多个定义错误
- 使用VS Code和CMake Tools运行自定义命令
- 使用mysql c++连接器的未定义引用
- 我的自定义使用 std::unordered_map 的性能非常慢
- 在 C++17 中,是否未定义使用无锁原子学保护从信号处理程序传递的数据?
- MSVC:无法识别的模板声明/定义(使用 Clang/GCC 编译)
- 如何在内核中定义/使用函数
- 定义使用此类型作为模板参数的类型和函数
- 在声明后对成员函数定义使用decltype
- K&R 风格的函数定义使用 g++ 编译
- 如何在 Windows 窗体中为事件函数定义使用单独的.cpp文件
- 定义/使用由预设组件构建的类(在c++中)
- 如何定义使用五倍相同参数类型的函数类型
- 在c++中使用整数排序(自定义使用std:: Sort)
- 错误LNK2005(已经在对象中定义)使用派生类的boost序列化
- 定义使用递归查找最后一位偶数的函数