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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:22:39+00:00 2026-06-17T03:22:39+00:00

void hello() { cout << helloworld << endl; } void hello(string s) { cout

  • 0
  void hello()
  {
    cout << "helloworld" << endl;
  }

  void hello(string s)
  {
    cout << "hello " << s << endl;
  }

  void doWork()
  {
    thread t1(static_cast<void ()>(&hello));
    thread t2(static_cast<void (string)>(&hello),"bala");
    t1.join();
    t2.join();
  }

Error:

thread.cc|19 col 42| error: invalid static_cast from type '<unresolved overloaded function type>' to type 'void()'                                                          
thread.cc|20 col 48| error: invalid static_cast from type '<unresolved overloaded function type>' to type 'void(std::string) {aka void(std::basic_string<char>)}'

I know I can use typedef of function pointers or a lambda.
Isn’t it possible to using static_cast?

  • 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-17T03:22:40+00:00Added an answer on June 17, 2026 at 3:22 am

    You must cast to function pointer types (not function types)

    thread t1(static_cast<void (*)()>(&hello));
                               ^^^
    

    A function type (eg. void()) is a type that denotes a function by its parameters and return types. However there can be no variables of these types in the program (except function themselves, these are lvalues of function types). However, there can be references to functions or pointers to functions, of which you want to use the latter.

    When you don’t try to make variables (or temporary objects) of function type (eg. you typedef a function type, or use it as a template parameter), its use is OK. std::function<void()> only uses the parameter to specify its parameters and return type, so its designers decided to use this sleek syntax. Internally, it doesn’t try to make variables with that type.

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

Sidebar

Related Questions

Code: #include <iostream> #include <thread> void hello() { std::cout << Hello World << std::endl;
Consider this code: #include <iostream> using namespace std; class hello{ public: void f(){ cout<<f<<endl;
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
public class Test extends Thread{ public void hello(String s){ System.out.println(s); } public void run(){
#include <iostream> std::string getMyName(void) { std:: cout << This is function getMyName << std::endl;
private: System::Void btn_entrar_Click(System::Object^ sender, System::EventArgs^ e) { string btn_texto = txt_login->Text->ToString(); MessageBox(NULL, Hello!, btn_texto.c_str(),
My programs looks like below #include <iostream> #include <thread> #include <exception> void hello() {
Okay, so I got two classes. class a{ public: a(){}; void print(){cout << hello};
When compiling the following code: #include <iostream> #include <thread> using namespace std; void hello()
int main(void) { char testStr[50] = Hello, world!; char revS[50] = testStr; } I

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.