Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #10794
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | static member linker problem |
| Date | 2011-10-11 14:53 +0200 |
| Organization | 1&1 Internet AG |
| Message-ID | <j71e8t$tul$1@online.de> (permalink) |
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::obj;
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::obj 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
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
static member linker problem Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-10-11 14:53 +0200
Re: static member linker problem Juha Nieminen <nospam@thanks.invalid> - 2011-10-11 12:58 +0000
Re: static member linker problem Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-10-11 15:10 +0200
Re: static member linker problem Victor Bazarov <v.bazarov@comcast.invalid> - 2011-10-11 09:45 -0400
Re: static member linker problem "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2011-10-11 17:24 +0200
Re: static member linker problem "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2011-10-11 17:26 +0200
Re: static member linker problem Victor Bazarov <v.bazarov@comcast.invalid> - 2011-10-11 12:17 -0400
Re: static member linker problem Leigh Johnston <leigh@i42.co.uk> - 2011-10-11 17:29 +0100
csiph-web