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 reorganize the code so that
- keep the
MyClassPtr
alias (it is shared across the project) - without "declaring"
MyClass
twice
code below:
class MyClass;
using MyClassPtr = std::shared_ptr<MyClass>;
class MyClass {
public:
static MyClassPtr createMyClassInstance();
private:
/*Other members & methods*/
}
I'm OK with the current implementation. But I would like to seek experienced guy's advice if the code can be improved.