c++ - Is there a way to overload operator= to have specific behavior for a function on right hand side -
i have class named image
non member function return image
.
image::image(const char * src); image::image& operator= (const image& p); image requestimg(std::string filename); //not member function
and use so:
image p = requestimg("grass.png");
this fine, however- able have requestimg
spawn thread loads image image
object(p), while modifying object have status of loading=true
.
in other words.
image p = requestimg("grass.png"); //image loading std::cout << p.loading << std::endl; //true //some time passes std::cout << p.loading << std::endl; //false
p
cannot have loading set true initially, not loading , not lead sane naming. realize member function easier- or passing pointer function, there way i've laid out?
you can leave image
is, , use std::async
, give std::future<image>
. can decide when need result of that:
#include <future> auto p = std::async(std::launch::async, &requestimg,"grass.png"); // load image asynchronously //some time passes // other work // need image auto img = p.get(); // blocking call, requires async call done loading image.
Comments
Post a Comment