Passing functions by value in a class...

This is a discussion on Passing functions by value in a class... within the C++ Programming forums, part of the General Programming Boards category; 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 ...

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

    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:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    [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:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(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,699
    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:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(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, 10:33 AM
  2. Functions in class and class variables.
    By Karakus in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2006, 02: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, 06:46 AM
  4. Replies: 3
    Last Post: 10-31-2005, 11:05 AM
  5. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 05:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21