mardi 29 mai 2018

Apply smart pointer on all objects

I'm trying to design a c++ application myself and apply these coding convention rules:
1. All objects have to be wrapped in a smart pointer. No raw pointer.
2. Containers such as std::vector, std::list,... will be declared as normal variable.
3. Always using HAS A, no inheritance.
Ex:

class Base {
public:
    void foo() {}
};

class Derived : public Base {
public: 
    void bar() {
        b->foo();
    }
private:
    shared_ptr<Base> b;
};

Could everyone tell me the pros and cons of these rules? And, Can you provide bad cases?

Aucun commentaire:

Enregistrer un commentaire