title: How to initialize grandparent's (const) property in grandchild in C++?
body: <p>I know this might look like a trivial question, but I haven't found really an elegant C++ solution to the following problem.</p>
  
  <p>I want to represent a complex (tree-like) hierarchy of a "world" of objects. Let's say <code>Animals</code>. Every animal has some basic const properties. 
  Like for example a <code>name</code>. Then it also has some methods, but they are not significant for this problem.</p>
  
  <pre><code>class Animal {
  public:
      const char *GetName() const;
  
  protected:
      const char *name;
  };
  
  class Insect : public Animal {
      ...
  };
  
  class Butterfly : public Insect {
      ...
  };
  </code></pre>
  
  <p>In this hierarchy I would like to initialize the <code>name</code> in every derived (grand)child. <strong>What is an elegant solution to this?</strong></p>
  
  <p>It is also important to say that in this "world" there be only instances of the tree leaves. That is, there will be no objects "Animal" or "Insect". But there will be objects "Butterfly", "Bee" or "Mosquito".</p>
  
  <p>I know the "standard" way to do this is to put <code>name</code> into constructor:</p>
  
  <pre><code>Animal::Animal(const  char *name) : name(name) {}
  Insect::Insect(const  char *name) : Animal(name) {}
  Butterfly::Butterfly() : Insect("Butterfly") {}
  </code></pre>
  
  <p>But if there are more of these properties, the derived classes need also some initialization and the hierarchy has more levels it can become quite a mess:</p>
  
  <pre><code>Animal::Animal(const  char *name) : name(name) {}
  Vertebrate::Vertebrate(const  char *name) : Animal(name) {}
  Mammals::Mammals(const  char *name) : Vertebrate(name) {}
  Ungulate::Ungulate(const  char *name) : Mammals(name) {}
  Horse::Horse() : Ungulate("Horse") {}
  </code></pre>
  
  <p>Another option I can see is to drop the <code>const</code> and assign directly in the grandchild's constructor:</p>
  
  <pre><code>class Animal {
  public:
      const char *GetName() const;
  
  protected:
      std::string name;
  };
  
  Horse::Horse() {this-&gt;name = "Horse";}
  </code></pre>
  
  <p>But that is also not optimal, because the const is lost and it is more prone to errors (the initialization can be forgotten).</p>
  
  <p>Is there some better way to do this?</p>