As an experiment I wanted to check if I can derive a Cinder App class from std::enable_shared_from_this so I can pass a shared_ptr of my main app to its members as a way of communication/messaging between an App and it’s members(also between public members themselves) so something like this can be called from a member:
When trying it and calling
shared_from_this() in my App’s setup method, I got the
bad_weak_ptr exception. After looking it up I realized that the exception is because “Prior to calling shared_from_this on an object t, there must be a std::shared_ptr that owns t”, That made sense. When I looked at Cinder’s source, I saw that in headers such as AppMac or AppMsw, when calling the
main<T>() method, a raw pointer of AppT is created and casted as the desired App, not a shared pointer.
I know I could implement the same system with raw pointers and I was experimenting anyways but the question bugged me to be honest, If Cinder has fully embraced C++11 and is using its features like shared pointers in so many places, why not the main App? Is there any specific reason behind this design? Hypothetically if a Cinder App needed to be a part of a bigger ecosystem, it being a
shared_ptr might help.
I hope I’m making sense