[boost.asio] issues with io_service.run

Hi: Ok, I'm trying to use boost::asio::io_service::run as follows. At the top of a .hpp file I have: typedef boost::asio::io_service FolderMonitoringService; I can pass this to a constructor requiring an io_service as follows: boost::asio::dir_monitor dm(FolderMonitoringService); however when I try to do: FolderMonitoringService.run(); I get 2 c2143 errors. 1>d:\work\access for everyone\sibelius access\sibeliusaccessserver\utility.cpp(127): error C2143: syntax error : missing ';' before '.' 1>d:\work\access for everyone\sibelius access\sibeliusaccessserver\utility.cpp(127): error C2143: syntax error : missing ';' before '.' If I remove the typedef previously shown, this line: FolderMonitoringService.run(); Compiles fine, but the line: boost::asio::dir_monitor dm(FolderMonitoringService); will not compile giving c2061, solved with the typedef-thanks igor! I've tried boost.ref, with know success. The function signature of the dir_monitor's constructor is: explicit basic_dir_monitor(boost::asio::io_service &io_service) Dir_Monitor is typedef'd to be basic_dir_monitor. Can anybody please tell me why the run function is causing an issue and how to fix this issue. Regards Sean.

On 02/20/2011 02:17 PM, Sean Farrow wrote:
Hi:
Ok, I’m trying to use boost::asio::io_service::run as follows.
At the top of a .hpp file I have:
typedef boost::asio::io_service FolderMonitoringService;
I can pass this to a constructor requiring an io_service as follows:
boost::asio::dir_monitor dm(FolderMonitoringService);
however when I try to do:
FolderMonitoringService.run();
You are trying to call a non-static method on the class. You need an instance of io_service. -- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com

typedef boost::asio::io_service FolderMonitoringService;
I can pass this to a constructor requiring an io_service as follows:
boost::asio::dir_monitor dm(FolderMonitoringService);
You should pass an instance, not a type name.
however when I try to do:
FolderMonitoringService.run();
You should call run() member-function on an instance, not on a type name.

Hi: Ok, I thought as I'd used typedef this was an instance. Could somebody given the code provided in the last message adapt this to show me what I should be doing? Thanks Sean. -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Igor R Sent: 21 February 2011 00:03 To: boost-users@lists.boost.org Subject: Re: [Boost-users] [boost.asio] issues with io_service.run
typedef boost::asio::io_service FolderMonitoringService;
I can pass this to a constructor requiring an io_service as follows:
boost::asio::dir_monitor dm(FolderMonitoringService);
You should pass an instance, not a type name.
however when I try to do:
FolderMonitoringService.run();
You should call run() member-function on an instance, not on a type name. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 02/20/2011 04:31 PM, Sean Farrow wrote:
Hi: Ok, I thought as I'd used typedef this was an instance. Could somebody given the code provided in the last message adapt this to show me what I should be doing? Thanks Sean.
Please don't top-post: http://www.boost.org/community/policy.html#quoting A typedef is sort of like giving the type an alias you can use later. If you want to instantiate the type you need to do something like: FolderMonitoringService folder_service; boost::asio::dir_monitor dm(folder_service); ... ... folder_service.run(); The following slides and video from BoostCon'10 might be helpful if you are just starting with ASIO. slides: http://www.objectmodelingdesigns.com/boostcon10/ video: http://boostcon.blip.tv/file/4171562/ michael -- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com
participants (3)
-
Igor R
-
Michael Caisse
-
Sean Farrow