title: c++ naming class Objects with variables
body: <p>I am working through a c++ problem set for fun.  I am creating a loop which will add objects to a class with random characteristics.  One of these random characteristics is the object name.  I have a program which randomly generates names for the class object, but I cannot figure out how to assign those names to the class objects. </p>
  
  <p>Here is my class and it's constructor:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include "windows.h"
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;array&gt;
  #include &lt;time.h&gt;
  #include &lt;conio.h&gt;
  
  class Bunny
  {
  public:
      char fname;
      int sex, age, color, status;
      Bunny(int, int, int, int);
      int s() { return (sex); }
      int a() { return (age); }
      int c() { return(color);}
      int st() { return (status);}
  };
  
  Bunny::Bunny(int s, int a, int c, int st)
  {
      sex = s;
      age = a;
      color = c;
      status = st;
  }
  </code></pre>
  
  <p>This is the Loop which generates "bunny" information.</p>
  
  <pre><code>std::string name;
  for (n = 0; n &lt; 1; n++)
  {
      int num = std::rand() % 5;
      int s = std::rand() % 2;
      std::string f = "Susan"; //this is normally a function which randomly gives names
      name = f;
      int a = 0;
      int c = std::rand() % 5;
      int st;
      if (rand() % 50 == 43) st = 1; else st = 0;
      Bunny name(s, a, c, st);
  }
  </code></pre>
  
  <p>if it was working right it should make a member like this:</p>
  
  <pre><code>   Bunny Susan(1, 0, 2, 0); 
  </code></pre>
  
  <p>This doesn't work because it creates a class object called "name" rather than "Susan".  How can I assign a class object a name through a variable rather than manually assigning the name in the code. </p>