我有一个曾经可以工作的C++。但是,包含<functional>标头后,编译失败并显示消息
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\std_function.h: In static member function 'static void std::_Function_base::_Base_manager<_Functor>::_M_clone(std::_Any_data&, const std::_Any_data&, std::true_type)':
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\std_function.h:167:11: error: '__dest' does not name a type
167 | ::new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
| ^~~~~~
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\std_function.h:167:17: error: expected ')' before '.' token
167 | ::new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
| ~ ^
| )
Run Code Online (Sandbox Code Playgroud)
我使用的是 MinGW GCC 8.2.0,但版本 9.2.0 也会出现这种情况。
这是测试套件的一部分。事实证明,该错误是由 CppUTest 进行运算符重载引起的。重载包含在 using 中-include/path/to/MemoryLeakDetectorNewMacros.h,因此仅通过查看代码并不能直接看出这一点。
使用 CppUTest 时的解决方案:确保 C++ STL 标头包含在 CppUTest 标头之前MemoryLeakDetectorNewMacros.h。有关详细信息,请参阅CppUTest 手册部分“解决与 STL 的冲突”。
| 归档时间: |
|
| 查看次数: |
917 次 |
| 最近记录: |