Boost logo

Ublas :

From: Georg Baum (Georg.Baum_at_[hidden])
Date: 2006-08-15 02:13:12


Am Montag, 14. August 2006 23:42 schrieb Ram:
> Hey,
>
> I am trying to get the following code to compile, but am not able to get
> it to do so. The example code on the webpage (where the matrix is defined
> in the int main() ) works fine.
>
> Thanks,
>
> RAm
>
> ------------------
> #include <boost/numeric/ublas/matrix.hpp>
> #include <boost/numeric/ublas/io.hpp>
>
> class foo {
> public:
> static boost::numeric::ublas::matrix<double> m (3,3);
> static int bar();
> };
>
> int foo::bar() {
> for (unsigned i = 0; i < m.size1 (); ++ i)
> for (unsigned j = 0; j < m.size2 (); ++ j)
> m (i, j) = 3 * i + j;
> std::cout << m << std::endl;
> }
>
> int main () {
> // using namespace boost::numeric::ublas;
>
> return 0;
> }
> -------------------

This is no ublas but a C++ problem: You must not initialize static data
members in the constructor. The following works:

class foo {
        public:
                static boost::numeric::ublas::matrix<double> m;
                static int bar();
};

boost::numeric::ublas::matrix<double> foo::m =
boost::numeric::ublas::matrix<double>(3,3);

> But I get the following error:
>
> g++ btest.cpp -o btest

You should always switch on warnings. I get:

x.cpp:6: error: invalid data member initialization
x.cpp:6: error: (use `=' to initialize static data members)

for your code with g++ 3.3.5, using the -W -Wall switches.

Georg