Hi,
I’m trying to get the hang of basic OOP, so I made this pointless code as a startinbg point:
#include <stdio.h>
class rectangle
{
public:
rectangle(void);
~rectangle(void);
…more function declarations
};
void main()
{
rectangle rocket;
return 0;
}
When I try to compile it, it tells me that there are undefined references to rectangle::rectangle and rectangle::~rectangle. If I remove the constructor and destructor or include some code, it doesn’t make a fuss. I know they’re not necessary, but why is it doing this?
You declared them in the class definition but did not provide implementations. For the default implementation just remove the semi-colons at the end of the declarations and add {};
That defines an empty constructor and destructor inline but that is really all you need for now. Or you could define them outside the class declaration like so:
rectangle::rectangle(void)
{
}
rectangle::~rectangle(void)
{
}
But in general this is a basic C++ question and doesn’t have as much to do with Haiku. But in the future I personally would like to see other languages (such as Ruby or Python) as first-class citizens when it comes to making simple Haiku apps. So one day you may not need to learn C++ to program Haiku. But that won’t be a reality for a while.
Thanks. I’ve been following darkwyrm’s tutorials, being more relevant to Haiku, and a widely used language. I believe he added the constructor as I did, so I didn’t really see how it went wrong, but this must have been an example of the theory, but code that doesn’t really work or do anything.