0

以下代码在 WINDOWS 和 LINUX 中可以很好地运行,但在 MAC 中失败:

template <typename T>
inline bool similar_fun(const std::vector<T> &a, const std::vector<T> &B, T threshold)
{
    using namespace std::placeholders;

    std::vector<T> differ;
    std::transform(a.begin(), a.end(), b.begin(),
        std::back_inserter(differ), std::bind(sub_fun<T>, _1, _2));

    return (std::accumulate(differ.begin(), differ.end(), static_cast<T>(0), Norm2<T>()) <= threshold);
}

开发平台是 Xcode 4,编译器是 Clang LLVM 1.0。我还确保编译器使用新的 C++ 标准 c++0x。错误信息如下:

   using namespace std::placeholders; *Expect namespace name
std::bind(sub_fun) *No member named "bind" in namespace std
4

1 回答 1

1

Clang LLVM 1.0 看起来很老了,它是从 2003 年开始的,所以你安装的标准库可能是一个 C++03 标准库,它没有placeholdersbind. 您可以尝试包含新的 C++11 标头,例如<array>以确认这一点。

如果我是对的,只需更新您的编译器:-)

于 2013-06-13T14:36:09.703 回答