Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 尝试用另一个类模板部分专用化一个类模板时,VS2013中出现错误_C++_Templates_Visual Studio 2013_Template Specialization - Fatal编程技术网

C++ 尝试用另一个类模板部分专用化一个类模板时,VS2013中出现错误

C++ 尝试用另一个类模板部分专用化一个类模板时,VS2013中出现错误,c++,templates,visual-studio-2013,template-specialization,C++,Templates,Visual Studio 2013,Template Specialization,给定以下类和函数模板: template <typename WrappedType, ParameterType ParamType, bool IsOutputParameter> class WrappedParameter; // Definition left out for brevity template <typename T> struct ParameterUnwrapper { static T UnwrapParameter(co

给定以下类和函数模板:

template <typename WrappedType, ParameterType ParamType, bool IsOutputParameter>
    class WrappedParameter; // Definition left out for brevity

template <typename T>
struct ParameterUnwrapper
{
    static T UnwrapParameter(const T& in_param)
    {
        return in_param;
    }
};

template <typename T, ParameterType ParamType, bool IsOutputParameter>
struct ParameterUnwrapper<WrappedParameter<T, ParamType, IsOutputParameter>>
{
    static T UnwrapParameter(const WrappedParameter<T, ParamType, IsOutputParameter>& in_param)
    {
        return in_param.GetWrapped();
    }
};

template <typename T>
T UnwrapParameter(T in_param)
{
    return Impl::ParameterUnwrapper<T>::UnwrapParameter(in_param);
}

template <typename T>
Impl::WrappedParameter<T, Impl::POINTER_PARAMETER, true> WrapOutputPointerParameter(T in_param)
{
    return Impl::WrappedParameter<T, Impl::POINTER_PARAMETER, true>(in_param);
}

template <typename MemFunc, typename ...Args>
HRESULT ExecuteAndLog(
    MemFunc in_memberFunction,
    const std::string& in_methodName,
    Args... args) //-> decltype((m_wrapped->*in_memberFunction)(UnwrapParameter(args)...))
{
    return ExecuteFunctorAndLog(
        [&]() { return (m_wrapped->*in_memberFunction)(UnwrapParameter(args)...); },
        in_methodName,
        args...);
}
给我一些错误:

error C2664: 'HRESULT (HACCESSOR,DBREFCOUNT *)' : cannot convert argument 2 from 'Impl::WrappedParameter<DBREFCOUNT *,POINTER_PARAMETER,true>' to 'DBREFCOUNT *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
see reference to function template instantiation 'ExecuteAndLog<HRESULT(__stdcall IAccessor::* )(HACCESSOR,DBREFCOUNT *),HACCESSOR, Impl::WrappedParameter<DBREFCOUNT *,POINTER_PARAMETER,true>>(MemFunc,const std::string &,HACCESSOR,Impl::WrappedParameter<DBREFCOUNT *,POINTER_PARAMETER,true>)' being compiled
with
[
    MemFunc=HRESULT (__stdcall IAccessor::* )(HACCESSOR,DBREFCOUNT *)
]
see reference to function template instantiation 'ExecuteAndLog<HRESULT(__stdcall IAccessor::* )(HACCESSOR,DBREFCOUNT *),HACCESSOR,Impl::WrappedParameter<DBREFCOUNT *,POINTER_PARAMETER,true>>(MemFunc,const std::string &,HACCESSOR,Impl::WrappedParameter<DBREFCOUNT *,POINTER_PARAMETER,true>)' being compiled
with
[
    MemFunc=HRESULT (__stdcall IAccessor::* )(HACCESSOR,DBREFCOUNT *)
]
更新: 下面是一个独立的示例:

我在VS2013中得到的错误是:

error C2664: 'int (int,int **,size_t *)' : cannot convert argument 2 from 'WrappedParameter<int **,ARRAY_PARAMETER,true>' to 'int **'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
see reference to function template instantiation 'int ExecuteAndLog<int(__thiscall A::* )(int,int **,size_t *),int,WrappedParameter<int **,ARRAY_PARAMETER,true>,size_t*>(MemFunc,const std::string &,int,WrappedParameter<int **,ARRAY_PARAMETER,true>,size_t *)' being compiled
with
[
    MemFunc=int (__thiscall A::* )(int,int **,size_t *)
]
错误C2664:“int(int,int**,size_t*)”:无法将参数2从“WrappedParameter”转换为“int**”
没有可执行此转换的用户定义的转换运算符,或者无法调用该运算符
请参阅正在编译的函数模板实例化“int ExecuteAndLog(MemFunc,const std::string&,int,WrappedParameter,size_t*)”的参考
具有
[
MemFunc=int(uu thiscall A::*)(int,int**,size\u t*)
]
我想出来了

问题是解包裹器的返回类型。有一次我把它的声明改成了

    template <typename T>
    auto UnwrapParameter(T in_param) -> decltype(Impl::ParameterUnwrapper<T>::UnwrapParameter(in_param))
模板
自动展开器(T in_参数)->decltype(Impl::ParameterUnwrapper::unwrapper::unwrapper(in_参数))
它被编译了。遗憾的是,编译器没有抱怨该函数的定义,而是信任它声明的返回值


我现在还有一些其他问题,但至少我取得了进展。

您缺少
参数类型
指针参数
m\u wrapped
Impl
的定义。如果您发布了其他人可以编译的内容,以查看相同的错误,这将非常有帮助。我试着为那些编译代码的人发明我自己的定义,我确实得到了与您报告的相同的错误,但我通过更改我定义的
POINTER\u参数
来修复它。(起初我将其作为与ParameterType不同的类型,然后我将其改为相同的类型)。您的代码离成为一个新的应用程序还有很长的路要走。我编造了一些你忽略了定义的东西。如果你能发布一个MCVE来显示你遇到的问题,这将是最好的,因为“真实代码”无疑与我不得不猜测的东西不同。(我在g++4.8.3中得到了一个与参数包相关的错误,不确定这是否是我的g++中的错误;Coliru没有得到错误)是的,它被修改了一点。明天我回去工作的时候,我会尽量让它更接近MCVE。嗯,你编译的版本可能是因为你添加了“操作符int*()const{return nullptr;}”。这也许对我的案子有用。。。
error C2664: 'int (int,int **,size_t *)' : cannot convert argument 2 from 'WrappedParameter<int **,ARRAY_PARAMETER,true>' to 'int **'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
see reference to function template instantiation 'int ExecuteAndLog<int(__thiscall A::* )(int,int **,size_t *),int,WrappedParameter<int **,ARRAY_PARAMETER,true>,size_t*>(MemFunc,const std::string &,int,WrappedParameter<int **,ARRAY_PARAMETER,true>,size_t *)' being compiled
with
[
    MemFunc=int (__thiscall A::* )(int,int **,size_t *)
]
    template <typename T>
    auto UnwrapParameter(T in_param) -> decltype(Impl::ParameterUnwrapper<T>::UnwrapParameter(in_param))