gfactory
Car.h
Go to the documentation of this file.
1
#ifndef CAR_H
2
#define CAR_H 1
3
4
#include "
gdl.h
"
5
6
class
Car
{
7
public
:
8
virtual
void
go
() = 0;
9
10
virtual
~Car
() =
default
;
11
12
float
generalCarVar
= 44;
13
14
// method to dynamically load factories
15
static
Car
*
instantiate
(
const
dlhandle
handle) {
16
17
if
(handle ==
nullptr
)
return
nullptr
;
18
19
// must match the extern C declaration in the derived factories
20
void
*maker = dlsym(handle,
"CarFactory"
);
21
22
if
(maker ==
nullptr
)
return
nullptr
;
23
24
typedef
Car
*(*fptr)();
25
26
// static_cast not allowed here
27
// see http://stackoverflow.com/questions/573294/when-to-use-reinterpret-cast
28
// need to run the DLL CarFactory function that returns the factory
29
fptr func =
reinterpret_cast<
fptr
>
(
reinterpret_cast<
void
*
>
(maker));
30
31
return
func();
32
}
33
};
34
35
36
#endif
// CAR_H
Car
Definition:
Car.h:6
Car::generalCarVar
float generalCarVar
Definition:
Car.h:12
Car::instantiate
static Car * instantiate(const dlhandle handle)
Definition:
Car.h:15
Car::go
virtual void go()=0
Car::~Car
virtual ~Car()=default
gdl.h
dlhandle
void * dlhandle
Definition:
gdl.h:15
examples
Car.h
Generated by
1.9.1