P
Paul
Hi,
I have a problem with the C++ spec 14.7.3.15 (see
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14761 for relevant
discussion).
It seems that the code (below) is impossible to get right, as you
cannot define a static data member of a template class if it ONLY has
a default-initializer...
the following code generates the following error:
$ g++ -Wall -W -pedantic -ansi -o test test.cpp
/tmp/ccnWckun.o(.text+0x11): In function `main':
: undefined reference to `foo<goo>::f'
collect2: ld returned 1 exit status
a real-life example of a 'goo' is boost::mutex, that can only be
default-constructed. I wanted it to be a static data member of a
template class, but I can't seem to define it. i can declare it just
fine, but not define.
Paul
struct goo
{
goo() : y(20) {}
int y;
private:
goo(const goo&);
};
template< typename S >
struct foo {
static goo f;
};
template< >
goo foo< goo >::f;
#include<iostream>
int main() {
foo<goo> x;
std::cerr << x.f.y << std::endl;
}
I have a problem with the C++ spec 14.7.3.15 (see
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14761 for relevant
discussion).
It seems that the code (below) is impossible to get right, as you
cannot define a static data member of a template class if it ONLY has
a default-initializer...
the following code generates the following error:
$ g++ -Wall -W -pedantic -ansi -o test test.cpp
/tmp/ccnWckun.o(.text+0x11): In function `main':
: undefined reference to `foo<goo>::f'
collect2: ld returned 1 exit status
a real-life example of a 'goo' is boost::mutex, that can only be
default-constructed. I wanted it to be a static data member of a
template class, but I can't seem to define it. i can declare it just
fine, but not define.
Paul
struct goo
{
goo() : y(20) {}
int y;
private:
goo(const goo&);
};
template< typename S >
struct foo {
static goo f;
};
template< >
goo foo< goo >::f;
#include<iostream>
int main() {
foo<goo> x;
std::cerr << x.f.y << std::endl;
}