从模板派生类调用模板基类的构造函数

Calling constructor of a template base class from a template derived class

本文关键字:构造函数 基类 派生 调用      更新时间:2023-10-16

我正在将一些代码从Visual Studio移植到Mingw GCC。这段代码在visualstudio上运行良好,但当我尝试在Mingw中构建它时,我会遇到以下问题。下方给出了代码

HeaderFile
template <MThread Thread>
class AFWork : public EffectFramework<Thread>
{
public:
    AFWork(HINSTANCE hinst, HWND hWindow,
                       const std::wstring& stSharedDataPath,
                       const std::wstring& stGameDataPath,
                       const std::wstring& stExtendedGameDataPath,
                       int nScrWidth, int nScrHeight);
    virtual ~AFWork(void);
    ...
    ...
};

上面引用的基类的另一个头文件是:

HeaderFile
template <MThread Thread>
class EffectFramework : public ktWin32Framework
{   
public:
    typedef boost::function<void (int window_no, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)> WindowProcedure;
    EffectFramework<Thread>( std::wstring& name,
                             std::wstring& dataDirPrefix,
                             VSYNC vsync,
                             HINSTANCE hinst, 
                             HINSTANCE hprevinst, 
                             LPSTR args, 
                             int mode,
                             IApplicationManager* appl_manager = NULL);
    ....
    ....
};

派生类构造函数的实现

                    template <MThread Thread>
                    AFWork<Thread>::AFWork(HINSTANCE hinst,
                                           HWND hWindow,
                                           const std::wstring& stSharedDataPath,
                                           const std::wstring& stGameDataPath,
                                           const std::wstring& stExtendedDataPath,
                                           int nScrWidth,
                                           int nScrHeight)
:  EffectFramework<Thread>::EffectFramework(wstring(L"ArtViewer"), wstring(L""), VSYNC::VSYNC_1, hinst, NULL, NULL, 0, NULL) <---ERROR
{
}

我得到的错误是这个

error: no matching function for call to 'T_Wrapper::EffectFramework<(T_Wrapper::T_Thread)0u>::EffectFramework(std::wstring, std::wstring, T_Wrapper::VSYNC, HINSTANCE__*&, int, int, int, int)'|

关于我为什么会出现这个错误以及如何解决它,有什么建议吗?

似乎来自EffectFramework的候选构造函数将std::wstring&作为第一个和第二个参数,但您正在传递临时变量。例如,如果您要传递全局变量,那么它应该可以工作。