gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:21:07 25 4
gpt4 key购买 nike

下面是一个给出编译时错误的程序。这主要与 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com