question - using boost::bind

L

Lutz Altmann

Hello,

i've a question related to bind and the use of function-objects
that "point" to an overloaded member-function.

look at this example:

class foo
{
public:

const foo& operator= (int);

};

with boost::bind i can create a function object pointing to the
operator= of a specific object:

foo arg;

x = bind<const foo&>(&foo::eek:perator=,ref(arg),_1);

now:
x(1);

is like :
arg = 1;

Thats very nice for me ;) - but the problem occur when i
overload operator= .

For example:

class foo
{
public:

const foo& operator= (int);
const foo& operator= (const foo&);

};

Now the bind doesnt work anymore: error message: "unresolved
overloaded function type"
Well, thats comprehensible for me - but i am asking myself if there is
a way to tell the compiler
which of these function he should us?
Is it possible, or do you know a work-around?

Regards,
Lutz
 
J

joe

Hello,

i've a question related to bind and the use of function-objects
that "point" to an overloaded member-function.

look at this example:

class foo
{
public:

const foo& operator= (int);

};

with boost::bind i can create a function object pointing to the
operator= of a specific object:

foo arg;

x = bind<const foo&>(&foo::eek:perator=,ref(arg),_1);

now:
x(1);

is like :
arg = 1;

Thats very nice for me ;) - but the problem occur when i
overload operator= .

For example:

class foo
{
public:

const foo& operator= (int);
const foo& operator= (const foo&);

};

Now the bind doesnt work anymore: error message: "unresolved
overloaded function type"
Well, thats comprehensible for me - but i am asking myself if there is
a way to tell the compiler
which of these function he should us?
Is it possible, or do you know a work-around?

Regards,
Lutz

I believe the following may work for you:

void (foo::*fp)(int) = &foo::eek:perator=; // tell the compiler which
version you want

now bind:
x = bind(fp, boost::ref(arg), _1);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top