P
Philipp Kraus
Hello,
I have written a header-only class with inline calls like in a header
file only like:
--header.hpp---
class myclass {
public :
private :
static anotherclass obj;
}
No i do the initialization in the same header file:
anotherclass myclass:
bj;
If I include this header in one cpp of another project, everything
works fine, but if the projects has more than one cpp
file, that includes the header, I get the linker error, that there are
duplicated calls for the myclass:
bj part.
I can create a cpp file with the initialization, but is there a
"header-only" solution to do the initialization without
linker problems eg a design pattern or anything else? My goal the
static members should be initialize within
their header file and the header files can be include more than once.
Thanks
Phil
I have written a header-only class with inline calls like in a header
file only like:
--header.hpp---
class myclass {
public :
private :
static anotherclass obj;
}
No i do the initialization in the same header file:
anotherclass myclass:
If I include this header in one cpp of another project, everything
works fine, but if the projects has more than one cpp
file, that includes the header, I get the linker error, that there are
duplicated calls for the myclass:
I can create a cpp file with the initialization, but is there a
"header-only" solution to do the initialization without
linker problems eg a design pattern or anything else? My goal the
static members should be initialize within
their header file and the header files can be include more than once.
Thanks
Phil