Displaying 2 results from an estimated 2 matches for "get_sptr".
Did you mean:
get_fptr
2019 Aug 29
2
enable_shared_from_this fails at runtime when inherited privately
...#include <memory>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/enable_shared_from_this.hpp>
#ifndef prefix
#define prefix std
#endif
class foo:
prefix::enable_shared_from_this<foo>
{
public:
prefix::shared_ptr<foo> get_sptr()
{
return shared_from_this();
}
};
int main()
{
auto a = prefix::make_shared<foo>();
auto b = a->get_sptr();
return 0;
}
This compiles fine, but throws a weak_ptr exception at runtime.
I'm aware, that the implementation requires, that
enable_shared...
2019 Aug 29
2
enable_shared_from_this fails at runtime when inherited privately
...t;
>> #include <boost/enable_shared_from_this.hpp>
>>
>> #ifndef prefix
>> #define prefix std
>> #endif
>>
>> class foo:
>> prefix::enable_shared_from_this<foo>
>> {
>> public:
>> prefix::shared_ptr<foo> get_sptr()
>> {
>> return shared_from_this();
>> }
>> };
>>
>> int main()
>> {
>> auto a = prefix::make_shared<foo>();
>> auto b = a->get_sptr();
>> return 0;
>> }
>>
>> This compil...