缺少 Directory_entry 的比较运算符

发布于 2024-10-21 08:45:50 字数 1056 浏览 2 评论 0原文

考虑以下程序:

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为你鎻心 2024-10-28 08:45:50

如果您无法在头文件中找到该运算符,那么您可能拥有不同版本的库?在 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.

回忆那么伤 2024-10-28 08:45:50

好的,显然这仅在新版本的库中受支持。在程序开始时将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文