Dec 13, 2010 at 1:09am UTC
Im using allegro, and im trying to add a header file to my code, but i get errors such as: [Linker Error] undefined reference to System::System() or [Linker Error] undefined reference to System::~System()
This is the main.cpp:
#include <Allegro.h>
#include "System.h"
int main(){
System system;
system.Setup();
BITMAP *buffer = create_bitmap( 640, 480 );
while ( !key[KEY_ESC] )
{
rectfill( buffer, 0, 0, 640, 480, makecol( 0, 0, 255 ) );
blit ( buffer, screen, 0, 0, 0, 0, 640, 480 );
clear_bitmap( buffer );
}
destroy_bitmap( buffer );
return 0;
}
END_OF_MAIN();
And this is the header file:
class System
{
private:
int screenWidth, screenHeight;
bool fullscreen;
public:
System();
~System();
void Setup();
};
void System::Setup()
{
allegro_init();
install_keyboard();
install_timer();
set_color_depth ( 16 );
fullscreen = false;
if ( fullscreen == true )
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
else
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
}
They are both in the same directory, but i don't know much about header files, can anyone tell me whats wrong with my code?
Dec 13, 2010 at 1:17am UTC
Did you define System::System() and System::~System() ? It doesn't look like you have - if you declare it in your header like that, you have to define it too.
Dec 13, 2010 at 1:20am UTC
Im rly noob to this header files stuff, how do i define the systems u just said?
Dec 13, 2010 at 2:22am UTC
I dont understand how the header files work, anyone know about this? Why isnt my code working?