I'm struggling with maybe a very simple hurdle but can't seem to understand how that works.
In my C++ project I want to provide lazy loaded classes. For this I thought of instantiating some fields of the type
std::shared_ptr<std::function<std::shared_ptr<MyClass>>> myClassLazyLoader;
At this point I'm not even sure anymore that is a valid approach, so please correct me if I'm completely off track.
I instantiate the field like this:
myClassLazyLoader = [] { return std::make_shared<MyClass>(); }
To invoke the function, I tried
myClassLazyLoader()
after which the compiler told me, as expected, that std::shared_ptr<std_function<... does not provide a call operator.
Naturally, I tried
(*myClassLazyLoader)()
but then it told me that std::function<... also does not provide a call operator which doesn't make any sense to me.
What am I doing wrong?
Thanks much in advance!
()- it should bestd::function<std::shared_ptr<MyClass>()>.