This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: linkage prob...


At 18.46 03/01/2003 +0200, Itay 'z9u2K' Duvdevani wrote:
Hey,
I need an "extern static const" decleration, but it is forbidden...
at the moment, my app won't link...
No, you don't need it to be static...

The following works for me (RedHat 8.0, GCC 3.2) :
decl.h:
namespace a
{
   namespace b
   {
       class x;
       // ...
   }
}

*********

x.h:
#include "decl.h"
class a::b::x
{
public:
   // ...
   static const int q1;
};

**********

x .cpp:
#include "x.h"
const int a::b::x::q1 = 4;
// ...

********

main.cpp:
#include "decl.h"
#include "x.h"
#include <iostream>
using namespace a;
using namespace a::b;

int main()
{
   std::cout << x::q1;        // will not link... g++ says:
   // main.cpp:8: undefined reference to `a::b::x::q1[in-charge](int const&)'
}
Couldn't compile without these correctiosn.

fwyzard


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]