Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-05-13 00:36:50


Susan Flynn wrote:

>
>>
>> In this context the library expects you to pass a function that takes
>> 'string' and returns nothing. However, you pass a member function, which
>> has implicit 'this' argument. I'd suggest this:
>>
>> #include <boost/bind.hpp>
>>
>> .....
>>
>> ->notify(boost::bind(&Report::PrintName, this, _1))
>>
>> HTH,
>> Volodya
>>
>
>
> Hi,
> Thanks for the quick reply. I tried your suggestion and it
> didn't get rid of the compile error. I had also previously
> tried making PrintName be a function (instead of a member
> function) and it didn't compile either.
> To simplify everything, I took the first example from the
> tutorial, first.cpp, and added a notify and a new, simple
> function (boost 1.32, libs/program_options/example). In
> first.cpp, change line 23:
> ("compression", po::value<int>(), "set compression level")
> ---to---
> ("compression", po::value<int>()->default(2)->notify(&PrintComp),
> "set compression level")
> then add this function before main:
> void PrintComp(int compr)
> {
> cout << "***Compression level is now " << compr << "\n";
> }
>
> The compile error is (still) 'invalid use of void expression'.
> Does my code above work for you?

No, but the attached does work. It differs only in using

  ->notifier

not

  ->notify

The 1.32 docs mistakenly had "notify" in one place, but I believe it's fixed
now. Sorry for confusion.

For calling member function, you'll still need 'bind'.

- Volodya




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