Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2003-10-29 14:39:01


I could reduce the linker problem to a template instantiation problem
for static member variables when using tthe BN trick. The following
code:

template<class D>
struct A {
   const D& derived() const {return *static_cast<const D*> (this);}
};

template<class T>
class B : public A<B<T> > {
public:
   T f() const { return zero_; }
private:
   static T zero_;
};

template<class T>
T B<T>::zero_ = 0;

int main()
{
   B<int> matrix;
   return matrix.derived().f();
}

when compiled with g++-3.3.2 (at least under MacOS X) gives the
following linker error:

/usr/bin/ld: Undefined symbols:
B<int>::zero_
collect2: ld returned 1 exit status

This causes problems with the uBlas sparse matrices. Sometimes a
workaround, explicitly defining the static member a second time will
work.

Matthias


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk