• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
In-class initialization of integral static const variables & Linker errors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

In-class initialization of integral static const variables & Linker errors


  • Subject: In-class initialization of integral static const variables & Linker errors
  • From: Guillaume Billard <email@hidden>
  • Date: Wed, 15 Jul 2009 17:16:38 +0200

Hello,

Here is a main.cpp file:

class Foo
{
public:
static int const foo = 0;
};

class Bar
{
public:
static int const bar = 0;
};

int main(int argc, char**)
{
return (argc == 1) ? Foo::foo : Bar::bar;
}

Trying to build this with Xcode 3.1.3 on Mac OS X 10.5.7, I get the following linker errors:

Undefined symbols:
  "Bar::bar", referenced from:
      __ZN3Bar3barE$non_lazy_ptr in main.o
  "Foo::foo", referenced from:
      __ZN3Foo3fooE$non_lazy_ptr in main.o
ld: symbol(s) not found

Can anyone tell me what is wrong here?
From what I understand, in-class initialization of integral static const variables is allowed in C++.
It also appears that one "can take the address of a static member if (and only if) it has an out-of-class definition."
http://www.research.att.com/~bs/bs_faq2.html#in-class
I don't know the insides of the ternary operator, but I reckon I'm not doing that here.

Thanks.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: In-class initialization of integral static const variables & Linker errors
      • From: Michael Crawford <email@hidden>
  • Prev by Date: Re: GDB problems and version
  • Next by Date: Re: GDB problems and version
  • Previous by thread: Re: GDB problems and version
  • Next by thread: Re: In-class initialization of integral static const variables & Linker errors
  • Index(es):
    • Date
    • Thread