c++ - 错误 C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'

标签 c++ visual-studio c++11

下面是一个给出编译时错误的程序。这主要与 D 类中的 Boo 函数有关。我最终尝试使用多个线程来调用 solve 方法,但目前这对我来说似乎不太有效,无法做到这一点。

错误是:

1>d:\dummy\project1\trash.cpp(37): warning C4101: 'd': unreferenced local variable
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(240): error C2672: 'std::invoke': no matching overloaded function found
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(248): note: see reference to function template instantiation 'void std::_LaunchPad<_Target>::_Execute<0,1>(std::tuple<void (__thiscall A::* )(C),C> &,std::integer_sequence<_Ty,0,1>)' being compiled
1>        with
1>        [
1>            _Target=std::unique_ptr<std::tuple<void (__thiscall A::* )(C),C>,std::default_delete<std::tuple<void (__thiscall A::* )(C),C>>>,
1>            _Ty=::size_t
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(247): note: see reference to function template instantiation 'void std::_LaunchPad<_Target>::_Execute<0,1>(std::tuple<void (__thiscall A::* )(C),C> &,std::integer_sequence<_Ty,0,1>)' being compiled
1>        with
1>        [
1>            _Target=std::unique_ptr<std::tuple<void (__thiscall A::* )(C),C>,std::default_delete<std::tuple<void (__thiscall A::* )(C),C>>>,
1>            _Ty=::size_t
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(244): note: while compiling class template member function 'void std::_LaunchPad<_Target>::_Run(std::_LaunchPad<_Target> *) noexcept'
1>        with
1>        [
1>            _Target=std::unique_ptr<std::tuple<void (__thiscall A::* )(C),C>,std::default_delete<std::tuple<void (__thiscall A::* )(C),C>>>
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(232): note: see reference to function template instantiation 'void std::_LaunchPad<_Target>::_Run(std::_LaunchPad<_Target> *) noexcept' being compiled
1>        with
1>        [
1>            _Target=std::unique_ptr<std::tuple<void (__thiscall A::* )(C),C>,std::default_delete<std::tuple<void (__thiscall A::* )(C),C>>>
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(259): note: see reference to class template instantiation 'std::_LaunchPad<_Target>' being compiled
1>        with
1>        [
1>            _Target=std::unique_ptr<std::tuple<void (__thiscall A::* )(C),C>,std::default_delete<std::tuple<void (__thiscall A::* )(C),C>>>
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thread(48): note: see reference to function template instantiation 'void std::_Launch<std::unique_ptr<std::tuple<void (__thiscall A::* )(C),C>,std::default_delete<_Ty>>>(_Thrd_t *,_Target &&)' being compiled
1>        with
1>        [
1>            _Ty=std::tuple<void (__thiscall A::* )(C),C>,
1>            _Target=std::unique_ptr<std::tuple<void (__thiscall A::* )(C),C>,std::default_delete<std::tuple<void (__thiscall A::* )(C),C>>>
1>        ]
1>d:\trash\project1\trash.cpp(26): note: see reference to function template instantiation 'std::thread::thread<void(__thiscall A::* )(C),C&,void>(_Fn &&,C &)' being compiled
1>        with
1>        [
1>            _Fn=void (__thiscall A::* )(C)
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(240): error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(240): note: With the following template arguments:
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(240): note: '_Callable=void (__thiscall A::* )(C)'
1>c:\program files (x86)\microsoft visual studio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(240): note: '_Types={C}'
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

代码是:

class C {
};

class A {
public:
    virtual void solve(C c) = 0;
};

class B:A {
public:
    void solve(C c) {};
};

class D {
public:
    void Boo(B* b, C &c)
    {
        auto thread1 = std::thread(&A::solve,c);
        thread1.join();
    }
};

int main()
{
    B b;
    C c;
    D d;
}

感谢您的宝贵时间! :)

最佳答案

问题是您尝试使用错误的参数调用 void Container::DrawContainer(),在您的上下文中 *this 是 Screen 类型但 void Container::DrawContainer() 除了接收 Container 类型的参数。

你可能想做的是:

void Screen::Display(Container* PBC,  Sorter &Solution)
{
    auto thread1 = std::thread(&Container::DrawContainer, PBC); 
    thread1.join();
}

关于c++ - 错误 C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47419115/

相关文章:

c++ - 如何在 Ubuntu 和 C/C++ 下拔出 USB 设备而不重新启动

c++ - 如何使用Arduino Serial.println使用 float 打印字符串

c# - MsBuild 任务和属性范围

c# - 在 Linux 中运行 Microsoft Visual Studio C# 项目

c++11 - 是否可以指示 `Gtk::TreeView` 显示自定义类型?

c++ - 递归模板 : object<auto_ptr<object>>

C++(在基于数组的堆栈中弹出)我们是否删除该元素?

c++ - 我应该链接到具有相同名称的 Debug 或 Release dll 吗?

c++ - 有没有办法从模板类的完整类型中获取其类型?

C++通过非负位移 move 一个范围?