缺少 Directory_entry 的比较运算符
考虑以下程序:
#include <iostream>
#include "boost/filesystem.hpp"
int main()
{
boost::filesystem::directory_entry d("test.txt");
boost::filesystem::directory_entry e("test.txt");
if (d == e) { // <---- error C2784
std::cout << "equal" << std::endl;
}
return 0;
}
此程序无法编译(Visual Studio 2005、Windows XP SP3),此错误有 17 种变体:
error C2784: 'bool std::operator ==(const std::stack<_Ty,_Container> &,
const std::stack<_Ty,_Container> &)' :
could not deduce template argument for
'const std::stack<_Ty,_Container> &' from
'boost::filesystem::directory_entry'
根据 文档(我仍在使用Boost 1.45),为directory_entry
定义了比较运算符,但我和编译器都找不到它们(我手动检查了标头)。我是否忽略了什么?难道是我在构建 boost 时犯了一个错误,也许是通过设置一些禁用这些运算符的选项?文档有误吗?谁能解释一下吗?
Consider the following program:
#include <iostream>
#include "boost/filesystem.hpp"
int main()
{
boost::filesystem::directory_entry d("test.txt");
boost::filesystem::directory_entry e("test.txt");
if (d == e) { // <---- error C2784
std::cout << "equal" << std::endl;
}
return 0;
}
This fails to compile (Visual Studio 2005, Windows XP SP3) with 17 variations of this error:
error C2784: 'bool std::operator ==(const std::stack<_Ty,_Container> &,
const std::stack<_Ty,_Container> &)' :
could not deduce template argument for
'const std::stack<_Ty,_Container> &' from
'boost::filesystem::directory_entry'
According to the documentation (I am still using Boost 1.45), there are comparison operators defined for directory_entry
, but neither me nor the compiler can find them (I checked the headers manually). Am I overlooking something? Could it be that I made a mistake when building boost, maybe by setting some option that disables these operators? Is the documentation wrong? Can anyone explain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您无法在头文件中找到该运算符,那么您可能拥有不同版本的库?在 Boost 1.45 中,操作符位于 operations.hpp< /a>.
If you were unable to locate the operator in the header file, then maybe you have a different version of the library? In Boost 1.45, the operator is located in operations.hpp.
好的,显然这仅在新版本的库中受支持。在程序开始时将
BOOST_FILESYSTEM_VERSION
定义为 3 解决了该问题。Ok, apparently this is only supported in the new Version of the library. Defining
BOOST_FILESYSTEM_VERSION
as 3 at the start of the program fixed the problem.