diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 5de7061..b4b0cf7 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -15774,18 +15774,19 @@ Avoid code bloat. It could be a base class: struct Link_base { // stable - Link* suc; - Link* pre; + Link* suc = nullptr; + Link* pre = nullptr; }; template // templated wrapper to add type safety struct Link : Link_base { + explicit Link(const T& v) : val(v) { } T val; }; struct List_base { - Link_base* first; // first element (if any) - int sz; // number of elements + Link_base* first = nullptr; // first element (if any) + int sz = 0; // number of elements void add_front(Link_base* p); // ... }; @@ -15794,7 +15795,7 @@ It could be a base class: class List : List_base { public: void put_front(const T& e) { add_front(new Link{e}); } // implicit cast to Link_base - T& front() { static_cast*>(first).val; } // explicit cast back to Link + T& front() { static_cast*>(first)->val; } // explicit cast back to Link // ... };