MSVC不会一直发出C2893吗?错误? [英] MSVC Doesn't issue C2893 consistently ? Bug?
问题描述
start_thread2和start_thread3线程中的代码是否应该调用?
http://stackoverflow.com/questions/42236085/msvc-inconsistent-c293-failed-to-specialize- function-template
嗨obidan2,
感谢您在此处发帖。
>> 我知道您应该使用std :: ref来获取 reference_wrapper并按值传递,但我不明白为什么代码在一种情况下编译而不是另一种情况。有人可以解释为什么它使用bind编译好但是
不是线程,为什么它不能用start_thread1编译?
仅限功能b 对可调用函数对象的inds参数。如果你不使用std:ref,也可以编译代码,但它将是函数参数对象,而不是
的实例
希望这对您有所帮助。
Should the code in the start_thread2 and start_thread3 thread calls not compile ?
http://stackoverflow.com/questions/42236085/msvc-inconsistent-c293-failed-to-specialize-function-template
Hi obidan2,
thanks for posting here.
>>I know you should use std::ref in order to get a reference_wrapper and pass it by value,but I don't understand why code compiles in one case and not the other. Can someone explain why it compiles fine with bind but not thread, and why it doesn't compile with start_thread1 ?
The std::thread(Fn&& F, Args&&... A) constructs an object that's associated with a new thread of execution and executes the pseudo-function INVOKE that's defined in <functional>. The std::reference_wrapper is a class template that wraps a reference in a copyable, assignable object. It is frequently used as a mechanism to store references inside standard containers. That's why we should use helper function like std::ref to construct a reference_wrapper from an argument. For example:
And the std::bind Function only binds arguments to a callable function object. The code could also be compiled if you don't use std:ref, but it will be the function parameter object, not the instance of std::reference_wrapper. For example:
For more information, please refer to this document below.
https://msdn.microsoft.com/en-us/library/mt771480.aspx
Hope this could be help of you.
这篇关于MSVC不会一直发出C2893吗?错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!