mardi 12 janvier 2021

C++ automatic shared_ptr type in class with macro

I'm trying to add to every class in my project an in-class alias for shared_ptr, like so:

class Foo {
/* ... */
public:
    using Ptr = std::shared_ptr<Foo>;
};

so that I can define shared pointers to Foo with the shorthand Foo::Ptr fooObjPtr;. Is there any method to create a macro that automatically adds the alias? Something like:

#define DEFINE_SHARED using Ptr = std::shared_ptr<__CLASS_NAME__>;

class Foo {
/* ... */
public:

    DEFINE_SHARED
};

Aucun commentaire:

Enregistrer un commentaire