Question

I'm new to the bimap functionality of the Boost libraries, and I'm having trouble passing a bimap into another function. My bimap looks like this:

typedef boost::bimap< int, int > bimap_type;
bimap_type bm;

I have an add_values() function that adds a set of values to the bimap:

add_values(int a, int b)
{
 bm.insert(bimap_type::value_type(a, b));
}

I then have a function that is meant to set the values of the bimap by getting them from a Singleton Class:

void set_values()
{
 MyClass::instance()->get_values(bm);
}

And, in MyClass, get_values() looks like this:

void get_values(bimap_type myBimap)
{
 myBimap.add_values(3, 5);
}

However, MyClass does not recognise 'bimap_type'. I try putting the typedef in a separate header file and including that in MyClass, but I get the error message:

'class bimap_type' has no member named 'add_values'

How can I successfully pass the bimap to this Singleton Class in order to fill it with values from the Class? Does anyone know?

Thanks a lot.

Was it helpful?

Solution

Er, boost::bimap itself doesn't have an add_values method and it's hard to tell from these code fragments why you're suddenly expecting one to appear.

OTHER TIPS

Consider renaming your functions: set_values() that calls get_values() that calls add_values() is one confusing call chain...

When you need to modify an object in a function, you have to take it by reference (or a pointer). The idea is that you must work with the same object inside and outside of the function. If you pass by value, function will see a copy, so anything it does with it does not reflect on original object.

// formerly known as add_values()
void initialize(bimap_type& bm, int a, int b)
{
    bm.insert(bimap_type::value_type(a, b));
}

And this is how you will call it:

initialize(myBitmap, 3, 5);

Make sure to update your whole call chain to pass by reference where appropriate, because currently your get_values() works with a copy too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top