This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: C++ static integer class constants...
- From: "Alex J. Dam" <alexjdam at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 16 Oct 2005 11:51:36 -0300
- Subject: Re: C++ static integer class constants...
- References: <435202e6.3d759d8f.4550.fffff1e6SMTPIN_ADDED@mx.gmail.com>
Hello.
On Sun, Oct 16, 2005 at 02:35:52AM -0500, John Ratliff wrote:
> class foo {
> public:
> static const int X = 5;
> static const int Y = 10;
> static const int Z = 15;
> };
>
> However, when I went to Linux, where I have g++ 3.3.5 (or possibly 3.3.6,
> but I think it's 3.3.5), the linker would complain about unresolved
> symbols.
I compiled a simple code using such constants here with no problems
using GCC 3.3.4 and 3.4.3.
> If I were to define the static variable in my implementation file, the
> linker would find the variables and go on its merry way. In other words, I
> could solve the problem by doing this:
>
> const int foo::X;
> const int foo::Y;
> const int foo::Z;
This is usually only needed when, e. g., you take the address of a
constant:
const int *x = &foo::X;
Do you have a minimal sample which does not work?
--
Alex. J. Dam