Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8031599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:09:20+00:00 2026-06-05T01:09:20+00:00

I have a two-layer object structure where the contained object has a deadline_timer and

  • 0

I have a two-layer object structure where the contained object has a deadline_timer and the outer object has the handler function, as:

class Internal
{
    asio::deadline_timer t;
public:
    void QueueTick(void (*handler)(boost::system::error_code const&))
    {
       t.expires_from_now(posix_time::millisec(250));
       t.async_wait(handler);
    }
};

class ForClients
{
    Internal I;
    void OnTick(boost::system::error_code const&) { /*...*/ }
    void Init()
    {
        I.QueueTick(boost::bind(&cdevXcite::OnTick, this, _1));
    }
};

The QueueTick() call is failing to compile in MSVS 2008 with “cannot convert parameter 1 from ‘boost::_bi::bind_t’ to ‘void (__cdecl *)(const boost::system::error_code &)'”.

If I make the timer member public and make a direct call to I.t.async_wait() with the same argument, it succeeds. Clearly, the handler’s signature is more special than what I’ve used in the QueueTick declaration; however, I can’t find a symbol that defines it and I don’t know how to interpret the metaprogramming going on inside the basic_deadline_timer<> template.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:09:23+00:00Added an answer on June 5, 2026 at 1:09 am

    An asio timer’s async_wait can be called with any callable type that can be called with a boost::system::error_code const& argument. There isn’t a single type anywhere that defines it, it just has to be callable with the documented argument type.

    The type of your QueueTick parameter is one such callable type, a pointer to a plain ol’ non-member function with the right signature:

    void QueueTick(void (*handler)(boost::system::error_code const&))
    

    But the result of boost::bind is a class type with an overloaded operator() which is not convertible to that function pointer type.

    There are a few ways to solve this, but the simplest is probably to follow async_wait itself and write QueueTick as a function template, accepting any type:

    class Internal
    {
      asio::deadline_timer t;
    public:
      template<WaitHandle>
        void QueueTick(WaitHandle handler)
        {
          t.expires_from_now(posix_time::millisec(250));
          t.async_wait(handler);
        }
    };
    

    The rest of the code would be unchanged.

    If that’s not an option (e.g. because QueueTick needs to be virtual) then you could use boost::function with can hold any callable object of the right signature:

    class Internal
    {
      asio::deadline_timer t;
    public:
      typedef boost::function<void(boost::system::error_code const&)> handler_type;
      void QueueTick(handler_type handler)
        {
          t.expires_from_now(posix_time::millisec(250));
          t.async_wait(handler);
        }
    };
    

    This will have a small overhead compared to the template version, due to constructing the boost::function object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two XML files. The first XML has a bunch of nodes that
I have a class that represents the state of the world. The class has
I have two arrays of objects that describe the structure of a neural network,
I have two UIImageViews on my object, and I'm trying to animate them to
I have a custom NSManagedObject which has several properties. I alloc and init two
I have four project apart from Presentation layer Business Logic Layer Interface layer Object
I have two executables that access a DLL containing Data Access Layer objects Each
I have two layers being drawn. A static background texture and a texture(png) with
I have advanced menu widget and two layers for home page and ordinary content
Let's say I have two char variables, and later on I want to concatenate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.