C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了c – 这是不正确使用std :: bind还是编译器错误?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用最新的快照构建clang与最新的TDM- Gcc头和库.编译时(使用-std = c 11标志):
#include <functional>
#include <iostream>

class Foo
{
    public:
        void Bar(int X)
        {
            std::cout << x << std::endl;
        }
};

int main()
{
    Foo foo;
    auto f = std::bind(&Foo::Bar,&foo,5);
    f();
    return 0;
}

我收到这些错误

In file included from Test.cpp:1:
C:\DevEnv\LLVM38\lib\gcc\mingw32\5.1.0\include\c++\functional:1426:7: error: static_assert Failed "Wrong number of arguments for pointer-to-member"
      static_assert(_Varargs::value
      ^             ~~~~~~~~~~~~~~~
C:\DevEnv\LLVM38\lib\gcc\mingw32\5.1.0\include\c++\functional:1440:7: note: in instantiation of template class 'std::_Bind_check_arity<void (Foo::*)(int) __attribute__((thiscall)),Foo *,int>' requested here
    : _Bind_check_arity<typename decay<_Func>::type,_BoundArgs...>
      ^
C:\DevEnv\LLVM38\lib\gcc\mingw32\5.1.0\include\c++\functional:1461:5: note: in instantiation of template class 'std::_Bind_Helper<false,void (Foo::*)(int) __attribute__((thiscall)),int>' requested here
    _Bind_Helper<__is_socketlike<_Func>::value,_Func,_BoundArgs...>::type
    ^
Test.cpp:16:14: note: while substituTing deduced template arguments into function template 'bind' [with _Func = void (Foo::*)(int) __attribute__((thiscall)),_BoundArgs = <Foo *,int>]
    auto f = std::bind(&Foo::Bar,5);
             ^
Test.cpp:16:14: error: no matching function for call to 'bind'
    auto f = std::bind(&Foo::Bar,5);
             ^~~~~~~~~
C:\DevEnv\LLVM38\lib\gcc\mingw32\5.1.0\include\c++\functional:1490:5: note: candidate template ignored: Couldn't infer template argument '_Result'
    bind(_Func&& __f,_BoundArgs&&... __args)
    ^
C:\DevEnv\LLVM38\lib\gcc\mingw32\5.1.0\include\c++\functional:1462:5: note: candidate template ignored: substitution failure [with _Func = void (Foo::*)(int) __attribute__((thiscall)),int>]
    bind(_Func&& __f,_BoundArgs&&... __args)
    ^
2 errors generated.

我是否误用std :: bind或者这是一些奇怪的编译器错误?它似乎只使用TDM Gcc编译.

解决方法

这段代码很好.

除非你做了一些奇怪或不支持你的安装,否则你的工具链会有一个bug.

对我来说,它似乎没有虑std :: bind的第二个参数是“this pointer”,并认为你实际上是将两个参数传递给Foo :: Bar(你不是),你可以’吨.

下一步是使用工具链的维护者来提高它.

https://llvm.org/bugs/show_bug.cgi?id=24372.

大佬总结

以上是大佬教程为你收集整理的c – 这是不正确使用std :: bind还是编译器错误?全部内容,希望文章能够帮你解决c – 这是不正确使用std :: bind还是编译器错误?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。