Ik heb zelf een thread class gemaakt om makkelijk threaded applicaties te kunnen schrijven. Maar het extenden van deze class wil nog niet helemaal lukken.
Bij de volgende extend gaat het mis:
Ik gebruik hem zo:
Dit is de fout melding:
/tmp/ccWjIeT2.o: In function `vdsock_thread::vdsock_thread()':
t.cpp:(.text._ZN13vdsock_threadC1Ev[vdsock_thread::vdsock_thread()]+0x8): undefined reference to `vtable for vdsock_thread'
collect2: ld gaf exit-status 1 terug
Snapt iemand wat ik fout doe?
C++:
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
26
27
28
29
30
31
| class vdsock_thread{ public: vdsock_thread(){} int start(void* _arg){ arg(_arg); int code = pthread_create(&_thread_id, NULL, &vdsock_thread::entry_point, this); return code; } protected: int run(void* arg){ setup(); execute(arg); } static void* entry_point(void* pthis){ vdsock_thread* pt = (vdsock_thread*)pthis; pt->run(pt->arg()); } void* arg() const{ return _arg; } void arg(void* a){ _arg = a; } virtual void setup(); virtual void execute(void*); private: pthread_t _thread_id; void* _arg; }; |
Bij de volgende extend gaat het mis:
C++:
1
2
3
4
5
6
7
8
9
10
| class A : public vdsock_thread{ public: void execute(void* arg){ std::cout << "Thread 1!\n"; usleep(1000000); std::cout << "Thread 1 again!\n"; usleep(1000000); } void setup(){} }; |
Ik gebruik hem zo:
C++:
1
2
| A t; t.start(NULL); |
Dit is de fout melding:
/tmp/ccWjIeT2.o: In function `vdsock_thread::vdsock_thread()':
t.cpp:(.text._ZN13vdsock_threadC1Ev[vdsock_thread::vdsock_thread()]+0x8): undefined reference to `vtable for vdsock_thread'
collect2: ld gaf exit-status 1 terug
Snapt iemand wat ik fout doe?