pointer to member function question

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-03-19T23:24:22Z Indexed on 2010/03/19 23:31 UTC
Read the original article Hit count: 312

Filed under:
|

Hello,

I'm trying to replicate a template I've used before with a member function, and it isn't going very well. The basic form of the function is

template<class T>
T Convert( HRESULT (*Foo)(T*))
{
    T temp;
    Foo(&temp); //Throw if HRESULT is a failure
    return temp;
}

HRESULT Converter(UINT* val)
{
    *val = 1;
    return S_OK;
}


int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << Convert<UINT>(Converter) << std::endl;
    return 0;
}

For the life of me, I can't get this to work with a member variable. I've read up on their syntax, and I can't seem to figure out how to make it work with templates.

The class would be something similar to

class TestClass
{ 
    HRESULT Converter(UINT* val)
    {
      *val = 1;
      return S_OK;
    }

}

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates