mercredi 6 septembre 2017

Static method return class's shared_ptr

In the following snippet, MyClass has a static method which returns its shared pointer. To make to code concise, we use the alias MyClassPtr for std::shared_ptr<MyClass>.

However, to accomplish this, we declare the class before declaring the shared pointer alias, which then follows the actual class declaration. It looks verbose.

Is there some way to simplify the code below.

class MyClass;
using MyClassPtr = std::shared_ptr<MyClass>;

class MyClass {
public:
    static MyClassPtr createMyClassInstance();

private:
/*Other members & method*/
}

Aucun commentaire:

Enregistrer un commentaire