Thread: Passing functions by value in a class...

  1. #1
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708

    Passing functions by value in a class...

    Code:
    c:\I.cpp: In method `bool InputBuffer::Create(long unsigned int = 10000)':
    c:\I.cpp: 73: no matches converting function `Thread' to type `DWORD (*)(void *)'
    c:\I.cpp: 31: candidates are: DWORD InputBuffer::Thread(void *)
    The problem is when I pass a certain function by address into another function in a class, the compiler won't allow it.
    Yet when I call the same function in a straight C program, it allows it to compile and the function runs smoothly.

    ...any ideas?

    I know that the type-checking is tighter with C++, but this is ridiculous.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    [code]


    THREAD
    NewThread( DWORD func(LPVOID), LPVOID params, DWORD *id = NULL)
    {
    static DWORD fakeIt = 0;

    if(id == NULL)
    {
    fakeIt++;
    id = &fakeIt;
    }
    return CreateThread(NULL, 0, func, params, 0, id);
    }








    //...hypothetical.cpp //...runs fine

    THREADFUNC s(LPVOID d){return 0;}





    int main(int argc, char *argv[])
    {
    char c = 's';

    THREAD t = NewThread(s, &c);

    while(ThreadIsActive(t)); //...wait...

    return 0;
    }


    [code]
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Is THREADFUNC the same as DWORD?

    If think it should be something like this (did not test it):
    Code:
    NewThread( DWORD (*func)(LPVOID), LPVOID params, DWORD *id = NULL)

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    No, it is a typedef for DWORD WINAPI. I am reading all about it now. It was because of some very partcular class restrictions which will require a slight rewrite....more later, thx
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 11:33 AM
  2. Functions in class and class variables.
    By Karakus in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2006, 03:29 AM
  3. Passing from functions in classes to another function in another class?
    By Robert_Sitter in forum Windows Programming
    Replies: 1
    Last Post: 12-13-2005, 07:46 AM
  4. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  5. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 06:08 AM