mardi 26 novembre 2019

the problem of "using Shared = std::shared_ptr<>" in base class and child class

I just solve a bug caused by "using Shared" in base class and child class. Like this:

class B: public A{
public:
    /**
     * Attention! This "using Shared" should be located before "using ResCallback " because
     * in class A, there is also a "using Shared".
     */
    using Shared = std::shared_ptr<B>;

    using ResCallback = std::function<void(const C& c, const char* data, size_t size, Shared b)>;

In the other file, there is class A:

class A{
public:
    using Shared = std::shared_ptr<A>;

In the past, I put "using ResCallback" before "using Shared" then it caused problem. This makes me doubt the "using Shared". Is there a better design style to avoid this stupid bug source?

Aucun commentaire:

Enregistrer un commentaire