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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:00:21+00:00 2026-05-28T14:00:21+00:00

I would like to create a thread passing a vector as parameter. but i

  • 0

I would like to create a thread passing a vector as parameter.
but i got the following errors:

error: invalid conversion from ‘int’ to ‘void* (*)(void*)’ [-fpermissive]

error: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’ [-fpermissive]

I have the following code:

#include <iostream>
#include <vector>
#include <pthread.h>

using namespace std;

void* func(void* args)
{
    vector<int>* v = static_cast<vector<int>*>(args);
    cout << "Vector size: " << v->size();
}

int main ( int argc, char* argv[] )
{

  vector<int> integers;
  pthread_t thread;


      for ( int i = 0; i < 10; i++)
        integers.push_back(i+1);

       // overheat call
       //pthread_create( &thread, NULL, func, static_cast<void*>(&integers));

       pthread_create( &thread, NULL,func,&integers);

       cout << "Main thread finalized" << endl;

 return 0;
}

How I can do it properly ?
Thanks

EDIT: forgot the includes posting here only; Revised.

I got new errors:

error: stray ‘\305’ in program
error: stray ‘\231’ in program

I am trying to know about it.

Thanks in advance.

FINAL EDIT : Thanks to all. Sorry, I had another int var called func in other location.
Thanks for your help.
  • 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-05-28T14:00:21+00:00Added an answer on May 28, 2026 at 2:00 pm

    You have forgotten to include <vector>; this confuses the compiler as it first fails to generate func, and then fails to identify it as a function in the call to pthread_create.

    Once you include that, your code should compile (and you can remove the static_cast<void*> if you like); but to work correctly you also need to call pthread_join before the vector goes out of scope, and return a value from func.

    UPDATE: your latest edit has broken the code: you should not cast func to void*, but leave it as a function pointer. This should work:

    pthread_create(&thread, NULL, func, &integers);
    

    Errors like stray ‘\305’ in program imply that you have some strange characters in your code, although they’re not in the code you’ve posted. Have a look at the lines that the error messages refer to.

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

Sidebar

Related Questions

Passing messages around with actors is great. But I would like to have even
I would like to create a process in my application. But after looking around
I would like to create a subclass of DispatcherObject to create my own thread-affined
I would like to create a new event-dispatch thread in Swing, and I'm having
I would like to create a worker thread that should be shared within other
I would like to create a :memory: database in python and access it from
I would like create my own collection that has all the attributes of python
I would like create a web service in ASP.Net 2.0 that will supports JSON.
Would like to create a strong password in C++. Any suggestions? I assume it
I would like to create a database backed interactive AJAX webapp which has a

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.