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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:10:08+00:00 2026-06-17T07:10:08+00:00

Is it possible to have overloads for functions that we need to span using

  • 0

Is it possible to have overloads for functions that we need to span using threads ?

I have a simple class called Complex.

class Complex
{
public:
    Complex():realPart_(0), imagPart_(0){}

    Complex(double rp, double ip) : realPart_(rp), imagPart_(ip) {}

    double & real() { return realPart_;}
    double & imag() { return imagPart_;}

    const double & real() const { return realPart_;}
    const double & imag() const { return imagPart_;}

    double square() const {return realPart_*realPart_ - imagPart_*imagPart_;}

    void display() const
    {
        std::cout << "Square of the Complex number (" << realPart_ << ") + i (" << imagPart_ << " ) is " << square() << std::endl;  
    }

    void display(unsigned nTimes) const {while(nTimes-- > 0)display();}

private:

    double realPart_;
    double imagPart_;

};

void Test3()
{
    Complex c1(1, 0.74), c2(2, 0.35);

    std::thread sqCalc1(&Complex::display, &c1);
    std::thread sqCalc2(&Complex::display, &c2);

    sqCalc1.join();
    sqCalc2.join();
}

I get errors when I build this code.

error C2661: 'std::thread::thread' : no overloaded function takes 2 arguments

If there is no overloaded display function that takes an unsigned then the code I have shown works fine.

  • 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-17T07:10:10+00:00Added an answer on June 17, 2026 at 7:10 am

    The problem is nothing to do with std::thread (the error is misleading), as can be shown by rearranging the code:

    auto memfunc = &Complex::display;
    std::thread sqCalc1(memfunc, &c1);
    std::thread sqCalc2(memfunc, &c2);
    

    The error will be on the first line now, because as other answers have said, the expression &Complex::display refers to an overloaded function and the compiler doesn’t know which one you mean.

    You can select the desired overload by telling the compiler the type of the function you are trying to call, with a cast or like this:

    void (Complex::*memfunc)() const = &Complex::display;
    std::thread sqCalc1(memfunc, &c1);
    std::thread sqCalc2(memfunc, &c2);
    

    Now you’ve explicitly requested the display overload that returns void and takes no arguments.

    If your compiler supports C++11 alias declarations you can make that easier to read:

    using memfunc_type = void (Complex::*)() const;
    memfunc_type memfunc = &Complex::display;
    std::thread sqCalc1(memfunc, &c1);
    std::thread sqCalc2(memfunc, &c2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have homework that I need to make a custom string class using C
Possible Duplicate: Overload ++ operator Say i have a class in which i overloads
I have a simple scenario that may or may not be possible. I have
Is it possible to have a free iPhone app that has say an initial
I know it's not possible to overload operators in as3, and have been using
I have a subset of a pointer class that look like: template <typename T>
I try to write a class that takes a tuple of functions as its
I have a class which has a constructor that takes a const char* .
I have two overloaded member functions with the following signatures: class MyClass { void
I have a one method interface and a class mocking that interface. The method

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.