Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are assigning a value to a variable that doesn't exist.</p> <p>Change:</p> <pre><code>ape::ape(int num) { tall = num; } </code></pre> <p>To:</p> <pre><code>ape::ape(int num) : number(num) { } </code></pre> <p>Moreover, I don't know why you wrote a destructor, and why you decided to make it <code>virtual</code>. By default, the compiler will generate an empty destructor (similar to yours, but not <code>virtual</code>). If you don't intend to do polymorphism (with inheritance and all that "stuff"), you may delete this destructor from your code as it only brings complexity for no gain.</p> <p>You also need to prefix your method <strong>definitions</strong> with the name of the class:</p> <pre><code>int ape::getNumber() // Note the "ape::" here { return number; } </code></pre> <p>One last thing:</p> <p>You problably want to change also your <code>main</code>:</p> <pre><code>int main() { ape asd(10); cout &lt;&lt; asd.getNumber() &lt;&lt; endl; } </code></pre> <p>Something put into <code>cout</code> only gets printed when one outputs <code>endl</code> or <code>flush</code> as the stream is buffered.</p> <p>Regarding your last edit:</p> <blockquote> <p>I guess I should probably add the error message: undefined reference to 'ape::ape(int)'</p> </blockquote> <p>You probably failed to link with <code>ape.o</code>. In your compilation folder, you should have your source files and a <code>.o</code> for every <code>.cpp</code>. You have to link those <strong>object files</strong> together to build your program. This message indicates that the linker is unable to find the definition for <code>ape::ape(int)</code>. That is he was probably not given the <code>ape.o</code> file.</p> <p>Long story short, here is what your compilation commands should look like (using g++):</p> <pre><code>g++ -o main.o -c main.cpp g++ -o ape.o -c ape.cpp g++ -o program main.o ape.o </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload