template<class YI_PTR_TYPE>
class CYIEnableSharedFromThis< YI_PTR_TYPE >
CYIEnableSharedFromThis<T> allows an object currently managed by a CYISharedPtr to safely generation additional CYISharedPtr internally.
- Deprecated:
- This class has been deprecated and may be removed in a future release. The std::enable_shared_from_this class should be used instead.
Consider the following example, which is going to result in a crash since your class instance may be managed by another mean, such as another shared pointer.
class MyClass
{
{
}
}
MyClass pClass = new MyClass();
...
This is where the CYIEnableSharedFromThis<T> comes into play. Inheriting from CYIEnableSharedFromThis<T> will provide convenient 'SharedFromThis()' function that will return a CYIWeakPtr<T> from the first CYISharedPtr<T> instance created. If the class is unmanaged by any CYISharedPtr<T>, 'SharedFromThis()' will return a null smart pointer.
{
{
}
}
MyClass pClass = new MyClass();
...
pSharedClass1.Reset();
- Warning
- Calling 'SharedFromThis()' on an unmanaged pointer will always return a null smart pointer.
-
Calling 'SharedFromThis()' from the Constructor will always return a null smart pointer.