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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:10:02+00:00 2026-05-27T03:10:02+00:00

error: invalid use of non-static data member ‘thread::tfun’ Class thread { typedef void* (th_fun)

  • 0

“error: invalid use of non-static data member ‘thread::tfun’”

Class thread {

  typedef void* (th_fun) (void*);

  th_fun *tfun;

  void create(th_fun *fun=tfun) {

    pthread_create(&t, NULL, fun, NULL);

}

}

How to have a function pointer inside a class?

Please note:- static deceleration will make the code compile. But my requirement is to hold the function per object.

  • 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-27T03:10:03+00:00Added an answer on May 27, 2026 at 3:10 am

    Your use of pthreads is fine, and you have no pointer-to-member-function here.

    The problem is that you’re trying to use a non-static member variable as a default parameter for a function, and you can’t do that:

    struct T {
       int x;
    
       void f(int y = x) {}
    };
    // Line 2: error: invalid use of non-static data member 'T::x'
    // compilation terminated due to -Wfatal-errors.
    

    The default argument must be something that’s — essentially — a global, or at least a name that doesn’t require qualification.

    Fortunately it’s an easy fix!

    Class thread {
    
      typedef void* (th_fun) (void*);
      th_fun* tfun;
    
      void create(th_fun* fun = NULL) {      // perfectly valid default parameter
         if (fun == NULL) {
            fun = tfun;                      // works now because there's an object
         }                                   // context whilst we're inside `create`
    
         pthread_create(&t, NULL, fun, NULL);
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the error Invalid argument supplied for foreach() even though the array being
OleDbDataAdapter internal error: invalid row set accessor: Ordinal=6 Status=UNSUPPORTEDCONVERSION All I'm doing is trying
With GCC 4.1.2, I get the error tmp.cpp:8: error: invalid function declaration for the
i encounter an error like Error 1 fatal error LNK1107: invalid or corrupt file:
Subsonic 2.2 is throwing the error subsonic Invalid cast from System.Int32 to System.Byte[] When
Example user input: PA1 9 //correct PJ1 9 //wrong, error printed Invalid row because
I'm getting the invalid lvalue error using gcc 3.4.6. The line that invokes the
How to log our own error messages (for ex: error due to invalid user
I'm getting this error: The remote certificate is invalid according to the validation procedure.
Error : Error 1 bin\Debug\Daemon.exe.manifest;bin\Release\Daemon.exe.manifest is an invalid value for the InputManifest parameter of

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.