Boost logo

Boost Users :

Subject: [Boost-users] Need help with compiling boost::function and ublas::matrix
From: archie14 (admin_at_[hidden])
Date: 2011-05-05 12:59:21


I am getting compiler error using boost::function and boost::numeric::ublas as
function return value. I am sure I am not declaring something right, but I
can't quite catch where (probably the "const" member function specifier).

Any help will be greatly appreciated.
Code to reproduce the problem is shown below. If

#include <vector>
#include <boost/function.hpp>
#include <boost/numeric/ublas/matrix.hpp>
using namespace boost::numeric::ublas;

class Foo
{
public:
        int bar() const
        {
                return 1;
        }

        const matrix<double>& stdev() const
        {
                return _stdev;
        }
private:
        matrix<double> _stdev;
};

typedef std::vector<Foo> container;

class invoker
{
public:
        invoker (container* cont,
                 boost::function<int (Foo*) > t) : f(t), _cont(cont)
        {
                for (container::iterator it = _cont->begin();
                                         it != _cont->end(); ++it)
                {
                        Foo& foo = *it;
                        int i = f(&foo);
                }
        }
// compiler generates error if following code
// is uncomennted together with the call in _tmain
// invoker (container* cont,
// boost::function<const matrix<double>& (Foo* const) > fmatrix)
// : _fmatrix(fmatrix), _cont(cont)
// {
// for (container::iterator it = _cont->begin();
// it != _cont->end(); ++it)
// {
// Foo& foo = *it;
// const matrix<double>& stddev = _fmatrix(&foo);
// }
// }
private:
        boost::function<int (Foo*) > f;
        boost::function<const matrix<double>& (Foo* const) > _fmatrix;
        container* _cont;
};

int _tmain(int argc, _TCHAR* argv[])
{
        container lst (5);
        std::fill(lst.begin(), lst.begin() + 5, Foo());

        invoker invbar(&lst, &Foo::bar);
// uncomment this line together with method in "invoker" to generate error
// invoker invstdev(lst, &Foo::stdev);
        return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net