Ik probeer in C++ een singleton object te implementeren. Als ik mijn programma probeer te compileren krijg ik tijdens het linken de volgende foutmelding: (ik heb g++ 2.95 en 3.2 geprobeerd)
Ik heb gezocht, maar ik zie echt geen fouten zitten in het programma. Of is dit een typische "feature" van gcc?
main.h:
main.cpp:
Ik heb uiteraard al op pagina's zoals http://www.informit.com/g...sp?g=cplusplus&seqNum=145 gekeken, maar de implementaties die daar staan lijken vrijwel exact op die van mij.
code:
1
2
3
4
5
6
7
| $ g++ main.cpp -c $ g++ main.o main.o: In function `cApplication::getInstance(void)': main.o(.text+0x39): undefined reference to `cApplication::instance' main.o(.text+0x68): undefined reference to `cApplication::instance' main.o(.text+0x92): undefined reference to `cApplication::instance' collect2: ld returned 1 exit status |
Ik heb gezocht, maar ik zie echt geen fouten zitten in het programma. Of is dit een typische "feature" van gcc?
main.h:
code:
1
2
3
4
5
6
7
8
9
10
| class cApplication {
public:
int run(int, char**);
static cApplication* getInstance();
private:
static cApplication* _instance;
protected:
cApplication();
}; |
main.cpp:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| #include <stdio.h>
#include "main.h"
cApplication::cApplication() {
}
int cApplication::run(int argc, char* argv[]) {
printf("Hello, World!\n");
return 0;
}
cApplication* cApplication::getInstance() {
if(cApplication::_instance==NULL) {
cApplication::_instance=new(cApplication);
}
return cApplication::_instance;
}
int main(int argc, char* argv[]) {
cApplication* application=cApplication::getInstance();
return application->run(argc,argv);
} |
Ik heb uiteraard al op pagina's zoals http://www.informit.com/g...sp?g=cplusplus&seqNum=145 gekeken, maar de implementaties die daar staan lijken vrijwel exact op die van mij.
[ Voor 10% gewijzigd door hellfire_ultd op 17-04-2004 19:23 ]