1
// C2893.cpp // OK in VS2013, Error in VS2015 // compile with: /EHsc #include <thread> // template <typename T_app> struct instance { void load() {;} }; // template <typename T_app> struct scene { T_app *p_app; void thread_load() { std::thread(&instance<T_app>::load, std::ref(p_app->app_inst) ).detach(); } }; // struct app { instance<app> app_inst; scene<app> app_scene; }; // int main() { app my_app; my_app.app_scene.p_app = &my_app; // OK in VS2013, Error in VS2015 my_app.app_scene.thread_load(); return 0; } 

Hello, I just updated to VS2015, the code in VS2013 is OK, how to correct the mistake of thread_load()? I read Breaking Changes in Visual C++ 2015, It must be Non-type template parameters problem, but I can not find a right way. Thanks.

3
  • what evil magic is that semicolon for? void load() {;} Commented Aug 6, 2015 at 7:42
  • 1
    it is equivalent to void load() {} The semicolon is a blank statement (and should be discarded by the compiler). Commented Aug 6, 2015 at 8:01
  • 1
    You can try to work around it: std::thread([&]{ p_app->app_inst.load(); }).detach() Commented Aug 6, 2015 at 9:46

1 Answer 1

1

The error is here std::ref(p_app->app_inst). The second parameter of std::thread should be a instance* in this context but p_app->app_inst is just a instance class.

So the answer is std::thread(&instance<T_app>::load, &p_app->app_inst ).detach(); without any lambda function.

Sign up to request clarification or add additional context in comments.

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.