Error C2248: 'std :: future <Worldlet> :: future': cannot access the private member declared in the class std :: future <Worldlet>

I get error C2248 when I try to compile this structure:

struct LoadingWorldlet { int x, z; std::future<Worldlet> result; }; 

I tried to make the result a link, but then I get error C2512. When I fix this error, I get C2582 in xutility. What is the way to fix this first error without getting the second, or how to fix both errors?

+4
source share
1 answer

std::future<Worldlet> with std::shared_future<Worldlet> may solve your problem with immediate compilation.

But the root of your problem is that maybe you want only one user std::future . You copy a struct somewhere that asks for two future to bind to the same promise source (or any source).

std::future intended to deliver its data once to one consumer. Therefore, if you want to move it, you must move it, and not copy it.

As your error indicates, you are compiling in MSVC2012. This compiler lacks an automatic constructor constructor and an assignment constructor. So try adding an explicit move constructor and the move-assign method.

 struct LoadingWorldlet { int x, z; std::future<Worldlet> result; LoadingWorldlet(LoadingWorldlet&& o):x(ox),y(oy),result(std::move(o.result)) {} LoadingWorldlet& operator=(LoadingWorldlet&& o) { x = ox; y = oy; result = std::move(o.result); return *this; } }; 

then avoid implicitly copying your LoadingWorldlet .

+4
source

Source: https://habr.com/ru/post/1497434/


All Articles