Help with first C++ class/pointers
<p>Hey guys, I taught myself PHP a few years back and am now in college and am relatively well versed in Java (and by that I really mean I'm a beginner but did my data structures course in it. I'll be taking Algorithms next semester)</p>

<p>In any case...I want to learn C++ and stumbled upon this:
<a href="http://newdata.box.sk/bx/c/" rel="nofollow">http://newdata.box.sk/bx/c/</a></p>

<p>What is really tripping me up right now is pointers...I THINK I get the theory but a really simple "program" isn't running right. It compiles but then there's a memory error.</p>

<p>I've decided to purchase C++ Primer after doing a few searches here on SO so it'll get here on Friday. Until then, can anyone tell me what is (horribly) wrong with this simple code:</p>

<pre><code>class Number {
public:
    string *owner;

    int getNum() {
        return *num;
    }

    int getTwice() {
        return *twice;
    }

    Number(int our_num, string me) {
        *num = our_num;
        *twice = 2 * *num;
        *owner = me;
    }

private: 
    int *num;
    int *twice;

};

int main()
{
Number *nbr3 = new Number(3,"Bob");

cout &lt;&lt; nbr3-&gt;getNum() &lt;&lt; endl;
cout &lt;&lt; nbr3-&gt;getTwice() &lt;&lt; endl;
cout &lt;&lt; nbr3-&gt;owner &lt;&lt; endl;
delete nbr3;
system("PAUSE");
return 0;
}
</code></pre>

<p>The errors appear in the constructor...like the *num=our_num part.</p>

<p>But isn't that line saying "set the value of the num pointer to our_num"? That IS what I want!</p>

<p>Thanks for helping with what I know to be a very silly and fundamental error...</p>
