A. McKenney
2011-06-13 08:58:47 UTC
I'm getting a warning message from a compiler for
a construct that I thought was required by the standard.
In A.h (included in mulitple files):
class XXX { public: static const int DefaultX = 1; }; //
declaration of XXX::DefaultX
In A.cpp:
const int XXX::DefaultX; // definition of XXX::DefaultX
With VC++ 2010, this results in a multiply-defined
warning message for XXX::DefaultX.
If I comment out the definition (in A.cpp),
everything compiles fine & without errors.
(The Solaris 10 compiler is happy either way.)
My understanding of the standard was
that the definition is required.
Am I wrong? Or is VC++ wrong?
FWIW, if I move the "= 1" from the declaration to the
definition, it compiles w/o error under VC++.
a construct that I thought was required by the standard.
In A.h (included in mulitple files):
class XXX { public: static const int DefaultX = 1; }; //
declaration of XXX::DefaultX
In A.cpp:
const int XXX::DefaultX; // definition of XXX::DefaultX
With VC++ 2010, this results in a multiply-defined
warning message for XXX::DefaultX.
If I comment out the definition (in A.cpp),
everything compiles fine & without errors.
(The Solaris 10 compiler is happy either way.)
My understanding of the standard was
that the definition is required.
Am I wrong? Or is VC++ wrong?
FWIW, if I move the "= 1" from the declaration to the
definition, it compiles w/o error under VC++.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]