Boost logo

Boost Users :

From: Paul Giaccone (paulg_at_[hidden])
Date: 2007-01-22 07:20:39


I am using Boost bind in conjunction with Boost unit test, as I have
many times before, but I can't get my code to compile. I've looked at
http://boost.org/libs/bind/bind.html#Troubleshooting but don't see
anything that covers my case.

Here is the line that is failing (with disguised variable names):

    test_suite -> add(BOOST_TEST_CASE(boost::bind(my_test, obj1, obj2,
obj3, 1.0, obj4, 10, 1E-9, results)));

and here is the error that Microsoft Visual C++ .NET is generating:

    main.cpp(152): error C2665: 'boost::bind' : none of the 2 overloads
can convert parameter 4 from type 'Obj3Type'

The variables obj3 and obj4 are of type Obj3Type and Obj4Type
respectively (see definitions below):

The function my_test is defined as:

void my_test(boost::shared_array<Vector>& a, boost::shared_array<Vector>& b,
                Obj3Type& c,
                const double d, const Obj4Type& e, const unsigned int f,
                const double g, boost::shared_array<std::pair<double,
std::valarray<double> > >& h)

where Obj3Type and Obj4Type are defined as:

class Obj3Type
{
    bool var1;
    unsigned int var2;
    unsigned int var3;
    double var4;
    double var5;
    MyType var6;
    boost::scoped_array<int> var7;
    boost::scoped_array<boost::scoped_array<double> > var8;
};

struct Obj4Type
{
    MyType var1;
    double var2;
    double var3;
    double var4;
    double var5;
    double var6;
    Vector var7;
    Vector var8;
    double var9;
    bool var10;
}

where MyType is an enumerated type and Vector is another struct of mine.
(Where I have used structs rather than classes, this is for convenience.)

Note that obj4 does not generate a compiler error, even when I move it
to appear before obj3 in the parameter list.

I wondered if it was necessary to overload operator= for Obj3Type as,
presumably, the compiler cannot generate it for the scoped arrays in
that struct but can for everything in Obj4Type, including Vector, for
which I have defined operator=. I wrote an operator= for Obj3Type, but
it made no difference to the compiler error. This was to be expected
really, as obj3 is passed by reference rather than by value.

Does it have anything to do with using structs instead of classes? I
can't see how that could be the case.

So what am I missing here?

Thanks for any help.


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