public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* linkage prob...
@ 2003-01-03 16:46 Itay 'z9u2K' Duvdevani
  2003-01-03 17:01 ` Andrea 'fwyzard' Bocci
  0 siblings, 1 reply; 2+ messages in thread
From: Itay 'z9u2K' Duvdevani @ 2003-01-03 16:46 UTC (permalink / raw)
  To: gcc-help

Hey,
I need an "extern static const" decleration, but it is forbidden...
at the moment, my app won't link...

summery:

decl.h:
namespace a
{
    namespace b
    {
        class x;
        // ...
    }
   
    using namespace b;
    // ...
}

*********

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;

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&)'
}

What am I doing wrong?
thanks...

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: linkage prob...
  2003-01-03 16:46 linkage prob Itay 'z9u2K' Duvdevani
@ 2003-01-03 17:01 ` Andrea 'fwyzard' Bocci
  0 siblings, 0 replies; 2+ messages in thread
From: Andrea 'fwyzard' Bocci @ 2003-01-03 17:01 UTC (permalink / raw)
  To: Itay 'z9u2K' Duvdevani; +Cc: gcc-help

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 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-01-03 17:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-03 16:46 linkage prob Itay 'z9u2K' Duvdevani
2003-01-03 17:01 ` Andrea 'fwyzard' Bocci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).