D
Damon
Hi,
I tried to perform a singleton pattern with lazy instantiation but
keep getting linker errors. Could someone advise what I'm doing
wrongly? I'm using gcc version 3.2.2. Thanks in advance.
--------------linker errors-------------
eve.o(.text+0x366): In function `main':
/usr/include/c++/3.2.2/i386-slackware-linux/bits/atomicity.h:50:
undefined reference to `eve::sq_note::sq_note[in-charge]()'
collect2: ld returned 1 exit status
make: *** [eve] Error 1
---------------basic_note.h------------
#ifndef BASIC_NOTE_H
#define BASIC_NOTE_H
#include "base/object.h"
namespace eve {
class basic_note : public object {
protected:
basic_note() {}
public:
virtual ~basic_note() {}
};
};
#endif
---------------sq_note.h---------------
#ifndef SQ_NOTE_H
#define SQ_NOTE_H
#include "basic_note.h"
namespace eve {
class sq_note : public basic_note {
private:
static sq_note* singleton;
public:
sq_note();
~sq_note() {
delete singleton;
}
static sq_note *instance() {
if( NULL==singleton ) {
singleton = new sq_note(); //problem with this line!
}
return singleton;
}
};
sq_note *sq_note::singleton = NULL;
};
#endif
Regards,
Damon
I tried to perform a singleton pattern with lazy instantiation but
keep getting linker errors. Could someone advise what I'm doing
wrongly? I'm using gcc version 3.2.2. Thanks in advance.
--------------linker errors-------------
eve.o(.text+0x366): In function `main':
/usr/include/c++/3.2.2/i386-slackware-linux/bits/atomicity.h:50:
undefined reference to `eve::sq_note::sq_note[in-charge]()'
collect2: ld returned 1 exit status
make: *** [eve] Error 1
---------------basic_note.h------------
#ifndef BASIC_NOTE_H
#define BASIC_NOTE_H
#include "base/object.h"
namespace eve {
class basic_note : public object {
protected:
basic_note() {}
public:
virtual ~basic_note() {}
};
};
#endif
---------------sq_note.h---------------
#ifndef SQ_NOTE_H
#define SQ_NOTE_H
#include "basic_note.h"
namespace eve {
class sq_note : public basic_note {
private:
static sq_note* singleton;
public:
sq_note();
~sq_note() {
delete singleton;
}
static sq_note *instance() {
if( NULL==singleton ) {
singleton = new sq_note(); //problem with this line!
}
return singleton;
}
};
sq_note *sq_note::singleton = NULL;
};
#endif
Regards,
Damon