Quantcast
Channel: Use of enable_shared_from_this with multiple inheritance - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Use of enable_shared_from_this with multiple inheritance

$
0
0

BI am using enable_shared_from_this in my code, and I am not sure if its usage is correct. This is the code:

class A: public std::enable_shared_from_this<A>
{
public:
    void foo1()
    {
        auto ptr = shared_from_this(); 
    }
};

class B:public std::enable_shared_from_this<B>
{
public:
    void foo2()
    {
        auto ptr = shared_from_this(); 
    }
};

class C:public std::enable_shared_from_this<C>
{
public:
    void foo3()
    {
        auto ptr = shared_from_this(); 
    }
};

class D: public A, public B, public C
{
public:
    void foo()
    {
        auto ptr = A::shared_from_this(); 
    }
};

Are these usage of make_shared_from_this() correct, assuming that they are always being called through shared_ptr of D?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images