template<typename T>
class CsPointer::CsEnableSharedFromThis< T >
CsEnableSharedFromThis is a base class which provides a mechanism for obtaining a CsSharedPointer to the current object.
This class supports retrieving a valid CsSharedPointer to this. In C++ "this" is a keyword which evaluates to a raw pointer whose value refers to the current object. If you construct a shared pointer by using the "this" raw pointer the shared pointer will assume responsibility and ownership for the current object. In most cases this will lead to undefined behavior.
To use this class your class must inherit from CsEnableSharedFromThis and pass the name of your class as a template parameter.
std::vector<CsSharedPointer<MyWidget>> widgetList;
{
public:
MyWidget::MyWidget() = default;
}
};
void addWidgetToList(MyWidget *ptr) {
CsSharedPointer<MyWidget> tmp = ptr->getSharedPtr();
widgetList.append(tmp);
}