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 9300595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:49:01+00:00 2026-06-18T22:49:01+00:00

Consider the following class: class Foo { private: void bar(const size_t); public: void foo();

  • 0

Consider the following class:

class Foo
{
   private:
      void bar(const size_t);
   public:
      void foo();
};

now Foo::foo() should start threads executing bar, so this is how it’s implemented:

void Foo:foo()
{
    auto handle = std::async(std::launch::async, &Foo::bar, this, 0);
    handle.get();
}

This works flawlessly with g++-4.6.3, but not with g++-4.5.2, the error message is

include/c++/4.5.2/functional:180:9: Error: must use ».« or »->« to call pointer-to-member function in »std::declval with _Tp = void (Foo::*)(long unsigned int), typename std::add_rvalue_reference<_Tp>::type = void (Foo::&&)(long unsigned int) (…)«, e.g. »(… -> std::declval with _Tp = void (Foo::*)(long unsigned int), typename std::add_rvalue_reference<_Tp>::type = void (Foo::*&&)(long unsigned int)) (…)«

So obviously the error lies within the old version of g++. It is possible to work around this issue by making the method public and introducing the following helper function:

void barHelp(Foo* foo, const size_t n)
{
    foo->bar(n);
}
void Foo:foo()
{
    auto handle = std::async(std::launch::async, barHelp, this, 0);
    handle.get();
}

However, making a method public isn’t the best design decision. Is there another way to work around this issue without changing the compiler and leaving the method private?

  • 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-18T22:49:02+00:00Added an answer on June 18, 2026 at 10:49 pm

    The problem appears to be that it won’t play nice with member functions. Perhaps you can std::bind the member function to your object first, before passing it to std::async:

    auto func = std::bind(&Foo::bar, this, std::placeholders::_1);
    auto handle = std::async(std::launch::async, func, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the following program: class Base { public: virtual void foo() const { cout
Consider the following example class Foo{ public: Foo(int i):x(i){} int x; }; void bar(Foo
Consider the following code: public class Bar { Foo foo; void Go() { foo
Consider the following Java class: public class Foo { public static void doStuff() {
Consider the following program: class A { public static void Foo() { } }
Consider the following code: class Foo(var name: String = bar) Now i try to
Consider the following code: public class Foo { private static final Object LOCK =
Consider the following MCVE : public class MyClass { private LinkedList<Foo> myList = new
Consider the following: class A{ //data members void foo() { bar();//is this possible? or
Consider the following code: class Foo; Foo& CreateFoo(); void Bar() { CreateFoo(); } In

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.