Когда я использую этот код: < /p> [code]#include "promise.hpp" #include using namespace std; int main() { stsb::promise tstint = stsb::promise(); thread waitthr = thread([tstint]() { // do some work tstint = 27; }); waitthr.detach(); // wait for result and do smth with it } < /code> с этим классом: < /p> #include #include #include
namespace stsb { template class promise { private: std::shared_ptr storage; std::shared_ptr ready; std::mutex mtx; public: inline promise(T& storage) : storage(std::make_shared(storage)), ready(new bool(false)), mtx() {} inline promise(void) : storage(new T()), ready(new bool(false)), mtx() {} inline promise(const promise& cp) : storage(cp.storage), ready(cp.ready), mtx() {} inline promise(promise&& cp) : storage(cp.storage), ready(cp.ready), mtx() {} inline promise& operator=(T&& value) { mtx.lock(); *(storage.get()) = value; mtx.unlock(); *(ready.get()) = true; return *this; } inline std::optional operator()() { mtx.lock(); if (!(*(ready.get()))) { mtx.unlock(); return std::nullopt; } auto tmp = *(storage.get()); mtx.unlock(); return tmp; } inline ~promise() {} }; } < /code> Я получаю эту ошибку: < /p> error: passing 'const stsb::promise' as 'this' argument discards qualifiers [-fpermissive] [/code] (в строке с tstint = 27; ) Я не понимаю, почему он проходит const stsb :: int> и не просто stsb :: int> кастинг в const class