Error C2975 in a template function implementation

寵の児 提交于 2019-12-25 00:24:34

问题


I've asked a similar question already but did not provide enough details. So I'm trying to re-phrase it with a better code sample. So here it is.

First off I'm using Visual Studio 2008 C++ compiler and I'm trying to implement a template to call a member method of a class.

The template is declared as such:

typedef void (*ON_CALL)(HWND);

template <typename CLASS, ON_CALL F>
class CMyTemplate
{
public:
    static void onProcess(CLASS* pDlg)
    {
        pDlg->SetTimer(100, 1, _onTimer);
    }

private:
    static void WINAPI _onTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
    {
        KillTimer(hwnd, idEvent);

        CLASS* pDlg = (CLASS*)CDialog::FromHandle(hwnd);
        if(pDlg)
        {
            pDlg->F(hwnd);
        }
    }
};

And it's actually called like so:

void CMyDialog::SomeMethod()
{
    CMyTemplate<CMyDialog, OnCall>::onProcess(this);    //error C2975
}

void CMyDialog::OnCall(HWND hWnd)
{
    //Do work ...
}

But that line that I marked above gives me this error:

error C2975: 'F' : invalid template argument for 'CMyTemplate', expected compile-time constant expression


回答1:


function OnCall is class member which implicit a this pointer, so it will not match the declaration



来源:https://stackoverflow.com/questions/48959965/error-c2975-in-a-template-function-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!