C++ vector pointer array
<p>have <code>struct_gene</code> and <code>struct_units</code>.
i read all <code>Struck_gene</code> values to <code>vector</code>.
How do i assign pointer for <code>struck_units.has_gene[i]</code> to point to some value in <code>struct_gene</code>vector so i dont have to write full copy of stuckt_gene
And after that read it.</p>

<p>I tried for some time but didn't manage to get working solution</p>

<p><a href="http://a.imageshack.us/img195/8607/001tfa.jpg" rel="nofollow">http://a.imageshack.us/img195/8607/001tfa.jpg</a></p>

<p>Edit -  Here's the code as retrieved by Jakobud:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;vector&gt;
#include &lt;time.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

using namespace std;
struct struct_gene {
    string name;
    string description;
};

struct struct_unit {
    string name;
    string surname;
    int age;
    int hunger;
    int happines;
    vector&lt;struct_gene&gt; *has_genes[12];
    struct_unit *maried_to;
    struct_unit *father;
    struct_unit *mother;
};

int main () {
    const int default_unit_count = 4;
    fstream gene_list;
    struct_gene * t_struct_gene;
    t_struct_gene = new struct_gene;
    gene_list.open("gene_list", ios::in);
    vector&lt;struct_gene&gt; vector_gene;
    //string name, description;

    gene_list &gt;&gt; t_struct_gene-&gt;name;
    getline(gene_list, t_struct_gene-&gt;description);
    while (gene_list) {
        vector_gene.push_back(*t_struct_gene);
        gene_list &gt;&gt; t_struct_gene-&gt;name;
        getline(gene_list, t_struct_gene-&gt;description);
    }
    delete t_struct_gene;

//   for (int i =0; i&lt;vector_gene.size(); i++) {
//      cout &lt;&lt;vector_gene[i].name &lt;&lt;" "&lt;&lt;vector_gene[i].description&lt;&lt;endl;
//   }
    struct_unit *t_struct_unit;
    t_struct_unit = new struct_unit;

    srand ( time(NULL) );

    vector&lt;struct_unit&gt; vector_units;

    for (int i=0; i&lt;default_unit_count; i++) {

        t_struct_unit-&gt;name = "unit_name";
        t_struct_unit-&gt;surname = "unit_surname";
        t_struct_unit-&gt;age = rand()%200;
        t_struct_unit-&gt;hunger = rand()%70 +30;
        t_struct_unit-&gt;happines = rand()%70 + 30;
        for (int i=0; i&lt;12; i++) {
            t_struct_unit-&gt;has_genes[i] = vector_gene[rand()%vector_gene.size()];
        }
        t_struct_unit-&gt;maried_to = NULL;
        t_struct_unit-&gt;father = NULL;
        t_struct_unit-&gt;mother = NULL;
        vector_units.push_back(*t_struct_unit);
    }

    for (int i=0; i&lt;vector_units.size(); i++) {
        cout &lt;&lt; vector_units[i].name &lt;&lt;" "&lt;&lt;vector_units[i].surname&lt;&lt;endl;
        cout &lt;&lt;"Age:"&lt;&lt; vector_units[i].age &lt;&lt;" Hunger:"&lt;&lt;vector_units[i].hunger&lt;&lt;" Happines:"&lt;&lt;vector_units[i].happines&lt;&lt;endl;
        for (int j=0; j&lt;0; j++) {
            cout &lt;&lt;vector_units[i].has_genes[j].name;
        }
        cout &lt;&lt;"==="&lt;&lt;endl;
    }
    delete t_struct_unit;
}
</code></pre>
