mercredi 9 octobre 2019

Can smart pointers be implicitly used as pointers?

Are smart pointers considered as pointers? And thus can they implicitly used as pointers?

Let's say I have the following class:

class MyClass {
    //...
    std::shared_ptr<AnotherClass> foo() { /*whatever*/ };
    void bar(AnotherClass* a) { /*whatever too*/ };
    //...
}

Then can I use MyClass the following way?

// m is an instance of MyClass
m.bar(m.foo());

Aucun commentaire:

Enregistrer un commentaire