title: Is there a way to initialize a class by function parameter in c++?
body: <p>I want to have a parent class which it stores all child class and the child class can have a derived classes which each classes is unique.
  that's why I want to initialize class in a function but a class is a parameter. I don't know what to describe but let's look at the code.
  I'm beginner btw.</p>
  <pre class="lang-cpp prettyprint-override"><code>class Child {
      string child_name;
  }
  class Jame : public Child {
      void sit() {
          cout &lt;&lt; &quot;Jame can sit&quot; &lt;&lt; endl; 
      }
  }
  class Harry : public Child {
      void sleep() {
          cout &lt;&lt; &quot;Harry can stand&quot; &lt;&lt; endl;
      }
  }
  
  class Parent {
      vector &lt;Child&gt; children;
      void addChild(string class_name) { //Prototype
          [classname] child; //EX. Jame child;
          child.child_name = class_name;
          
          children.push_back(child);
      }
      Child* getChild(string child_name) {
          for(int i = 0; i &lt; children.size(); i++)
              if(children.at(i).child_name == child_name)
                  return &amp;children.at(i);
      }
  };
  
  int main() {
  
      Parent parent;
      parent.addChild(&quot;Harry&quot;);
      Child* child = parent.getChildren(&quot;Harry&quot;);
      child-&gt;sleep(); //Harry can stand.
      child-&gt;sit(); //error: undefined function.
      
      return 0;   
  }
  </code></pre>
  <p>Something like this.
  If you have any other ways help me please, I'm very new and I don't know what it's called.</p>