Re: C++ static integer class constants...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux