Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple c++ constructor don't work (very basic)
    primarykey
    data
    text
    <p>Ok, so I've decided to read a little c++ now and then, just to get a basic understanding of the syntax. I am familiar with Java, and a little bit of Python. I have 'read' through a c++ for dummies book, and I thought I had the grip - until I tried to create the simplest class. The idea was <em>very</em> simple: a class (named ape) takes one parameter, an int, which is stored as a private field. It has one other function, a return function, which returns the field. The main() creates an instance, and calls the method to print out the variable. </p> <p>The idea was to use a string instead of an int, but I couldn't get it working, so I decided to use an int instead, which, obviously, wasn't working either. </p> <p>If it is to any interest I use Code::blocks, Windows 7 and the g++ compiler. </p> <p>Here are the classes: </p> <p>Main.cpp</p> <pre><code>#include &lt;iostream&gt; #include "ape.h" using namespace std; int main() { ape asd(10); cout &lt;&lt; asd.getNumber(); } </code></pre> <p>ape.h</p> <pre><code>#ifndef APE_H #define APE_H class ape { public: ape(int num); virtual ~ape(); int getNumber(); protected: private: int number; }; #endif // APE_H </code></pre> <p>and ape.cpp</p> <pre><code>#include "ape.h" using namespace std; ape::ape(int num) { tall = num; } ape::~ape() { //dtor } int getNumber() { return number; } </code></pre> <p>The error messages I get seems very random to me, as they are changing completely with every single change I make, and are not very self explaining. I can see how I sound like an arrogant fool, and that this whole mess is the compilers fault, but I really don't see any connection between the error messages and what's wrong in my code.</p> <p>Take it easy on me, first time here. :)</p> <p>I guess I should probably add the error message: <em>undefined reference to 'ape::ape(int)'</em> </p>
    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.
 

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