c++ - 是什么阻止了这段代码在 Visual C++ 6 中编译?
问题描述
我正在查看这个 GitHub 存储库,以替换 Visual C++ 6 中的 std::shared_ptr 以修改一些旧代码,但我发现这个库不兼容,因为编译器抛出了解析器错误。
我知道支持嵌套模板类和朋友类。但这是一个template<class U>
与模板不同的地方class shared_ptr
,也是朋友类引用自己的地方。
这个自引用模板朋友类的目的是什么?它是如何使用的?
shared_ptr
无需编译引用的库即可演示该问题:
template<class T>
class shared_ptr
{
template<class U>
friend class shared_ptr;
};
int main() {
return 0;
}
编译器抛出以下错误:
main.cpp(5) : error C2059: syntax error : '<end Parse>'
main.cpp(6) : see reference to class template instantiation 'shared_ptr<T>' being compiled
main.cpp(6) : error C2143: syntax error : missing ';' before '}'
main.cpp(6) : see reference to class template instantiation 'shared_ptr<T>' being compiled
main.cpp(6) : error C2238: unexpected token(s) preceding ';'
main.cpp(6) : see reference to class template instantiation 'shared_ptr<T>' being compiled
我不需要这个库,因为我已经能够通过使用 Boost 1.34.1 解决这个问题。但我想了解这个限制以及它的用途。
解决方案
推荐阅读
- kubernetes - 多个入口在 kubernetes 中不起作用
- java - JPA 请求问题:查询方法 public abstract java.util.List 的验证失败
- javascript - 自动触发点击 JavaScript 功能
- makefile - makefile“删除中间文件”只是有时
- ruby - Rspec 不模拟请求
- r - 在 R 中读取带有垂直矩形分隔符的 DAT 文件
- c - 在 C 程序中获取指针问题
- c++ - OpenCV fillPoly 与 floodFill 的差异
- c# - Azure 函数日志记录 - 双倍的日志条目?
- azure - Azure 规模集中 Windows VM 上的 Windows 自动更新