4

Below is a certain program that is giving compile time errors. This has to do mostly with function Boo in class D. I am eventually trying to use a number of threads to call the solve method but this does not seem to be working out too well for me at the moment to get that far.

The errors are:

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 ========== 

The code is:

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; } 

Thank you for your time! :)

6
  • 1
    Didn't you mean std::thread(&Container::DrawContainer,PBC); ? Commented Nov 21, 2017 at 17:38
  • I was just about to say reading MSVC error messages is giving me headaches, but then I saw what gcc had to say, and realized MSVC is great. Commented Nov 21, 2017 at 17:41
  • 1
    Container is derived from an abstract class so the compiler is complaining about it being unable to instantiate abstract class when I do std::thread(&Container::DrawContainer,PBC) Commented Nov 21, 2017 at 17:41
  • 1
    In your example, you'd need to write auto thread1 = std::thread(&B::solve,b,c);. Commented Nov 21, 2017 at 19:17
  • Thanks Piotr, you solved my problem. I don't know how to upvote your comment though, I am pretty new to being a registered user on this site. Commented Nov 21, 2017 at 21:22

2 Answers 2

0

The problem is that you are trying to invoke void Container::DrawContainer() with the wrong argument, in your context *this is of type Screen but void Container::DrawContainer() except to receive an argument of type Container.

What you probably meant to do is:

void Screen::Display(Container* PBC, Sorter &Solution) { auto thread1 = std::thread(&Container::DrawContainer, PBC); thread1.join(); } 
Sign up to request clarification or add additional context in comments.

1 Comment

I updated my question, maybe the problem is now explained better up there. Thank you for your time :)
0

You need to provide an object to invoke the non-static method on, like:

auto thread1 = std::thread(&A::solve, b, c); 

But this won't compile either because the method do not match. But you can either cast b to (A*) or change the Boo's parameter to A* a.

void Boo(A* a, C &c) { auto thread1 = std::thread(&A::solve, a, c); thread1.join(); } 

You can look see samples at http://en.cppreference.com/w/cpp/utility/functional/invoke.

There is similar question Error C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.