未能推导模板参数(errorC2783)

本文介绍了在C++中如何正确地使用模板函数。重点讲解了模板参数推导机制无法推导函数返回值的情况,并给出了在调用时显式指定返回值类型的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用模板函数时有一个原则:

模板参数推导机制无法推导函数返回值。


so,如果需要在返回值中使用模板,就必须在函数调用时,显式指明返回值类型。


template<typename T>
T*	GetInputData();

template<typename T>
VOID	SetInputData(T t);


INT*	xx;

SetInputData(123);
xx = GetInputData<INT>();


[1/4] Compile [x64] MyBlueprintFunctionLibrary.cpp 11>MyBlueprintFunctionLibrary.cpp(131): Error C2672 : “begin”: 未找到匹配的重载函数 11>xutility(1824): Reference C2672 : 可能是“_Ty *std::begin(_Ty (&)[_Size]) noexcept” 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : “_Ty *std::begin(_Ty (&)[_Size]) noexcept”: 无法从“const FAntQueryData”推导出“_Ty (&)[_Size]”的 模板 参数 11>xutility(1806): Reference C2672 : 或 “unknown-type std::begin(const _Container &) noexcept(<expr>)” 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : 未能使函数模板“unknown-type std::begin(const _Container &) noexcept(<expr>)”专用化 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : 用下列模板参数: 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : “_Container=FAntQueryData” 11>xutility(1807): Reference C2672 : "begin": 不是 "FAntQueryData" 的成员 11>AntSubsystem.h(441): Reference C2672 : 参见“FAntQueryData”的声明 11>xutility(1800): Reference C2672 : 或 “unknown-type std::begin(_Container &) noexcept(<expr>)” 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : 未能使函数模板“unknown-type std::begin(_Container &) noexcept(<expr>)”专用化 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : 用下列模板参数: 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : “_Container=const FAntQueryData” 11>xutility(1801): Reference C2672 : "begin": 不是 "FAntQueryData" 的成员 11>AntSubsystem.h(441): Reference C2672 : 参见“FAntQueryData”的声明 11>initializer_list(54): Reference C2672 : 或 “const _Elem *std::begin(std::initializer_list<_Elem>) noexcept” 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : “const _Elem *std::begin(std::initializer_list<_Elem>) noexcept”: 无法从“const FAntQueryData”推导出“std::initializer_list<_Elem>”的 模板 参数 11>MyBlueprintFunctionLibrary.cpp(131): Error C2672 : “end”: 未找到匹配的重载函数 11>xutility(1829): Reference C2672 : 可能是“_Ty *std::end(_Ty (&)[_Size]) noexcept” 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : “_Ty *std::end(_Ty (&)[_Size]) noexcept”: 无法从“const FAntQueryData”推导出“_Ty (&)[_Size]”的 模板 参数 11>xutility(1818): Reference C2672 : 或 “unknown-type std::end(const _Container &) noexcept(<expr>)” 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : 未能使函数模板“unknown-type std::end(const _Container &) noexcept(<expr>)”专用化 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : 用下列模板参数: 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : “_Container=FAntQueryData” 11>xutility(1819): Reference C2672 : "end": 不是 "FAntQueryData" 的成员 11>AntSubsystem.h(441): Reference C2672 : 参见“FAntQueryData”的声明 11>xutility(1812): Reference C2672 : 或 “unknown-type std::end(_Container &) noexcept(<expr>)” 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : 未能使函数模板“unknown-type std::end(_Container &) noexcept(<expr>)”专用化 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : 用下列模板参数: 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : “_Container=const FAntQueryData” 11>xutility(1813): Reference C2672 : "end": 不是 "FAntQueryData" 的成员 11>AntSubsystem.h(441): Reference C2672 : 参见“FAntQueryData”的声明 11>initializer_list(59): Reference C2672 : 或 “const _Elem *std::end(std::initializer_list<_Elem>) noexcept” 11>MyBlueprintFunctionLibrary.cpp(131): Reference C2672 : “const _Elem *std::end(std::initializer_list<_Elem>) noexcept”: 无法从“const FAntQueryData”推导出“std::initializer_list<_Elem>”的 模板 参数 11>MyBlueprintFunctionLibrary.cpp(131): Error C3536 : “<begin>$L1”: 初始化之前无法使用 11>MyBlueprintFunctionLibrary.cpp(131): Error C3536 : “<end>$L1”: 初始化之前无法使用 11>MyBlueprintFunctionLibrary.cpp(131): Error C2100 : 非法的间接寻址 Total time in Parallel executor: 0.93 seconds Total execution time: 1.52 seconds 帮我看下这个报错
03-19
C:\Qt\6.7.3\msvc2022_64\include\QtCore\qobject.h:262: error: C2672: “QtPrivate::makeCallableObject”: 未找到匹配的重载函数 C:\Qt\6.7.3\msvc2022_64\include\QtCore/qobject.h(262): error C2672: “QtPrivate::makeCallableObject”: 未找到匹配的重载函数 C:\Qt\6.7.3\msvc2022_64\include\QtCore/qobjectdefs_impl.h(612): note: 可能是“enable_if<'函数'>=0,QtPrivate::QSlotObjectBase*>::type QtPrivate::makeCallableObject(Functor &&)” C:\Qt\6.7.3\msvc2022_64\include\QtCore/qobject.h(262): note: 未能使函数模板“enable_if<'函数'>=0,QtPrivate::QSlotObjectBase*>::type QtPrivate::makeCallableObject(Functor &&)”专用化 C:\Qt\6.7.3\msvc2022_64\include\QtCore/qobject.h(262): note: 用下列模板参数: C:\Qt\6.7.3\msvc2022_64\include\QtCore/qobject.h(262): note: “Prototype=void (__cdecl QNetworkAccessManager::* )(QNetworkReply *)” C:\Qt\6.7.3\msvc2022_64\include\QtCore/qobject.h(262): note: “Functor=_Ty” C:\Qt\6.7.3\msvc2022_64\include\QtCore/qobjectdefs_impl.h(610): note: “std::enable_if_t<false,QtPrivate::QSlotObjectBase*>”: 未能使别名模板专用化 C:\Qt\6.7.3\msvc2022_64\include\QtCore/qobject.h(262): note: 模板实例化上下文(最早的实例化上下文)为 faceenterwindow.cpp(21): note: 查看对正在编译的函数 模板 实例化“QMetaObject::Connection QObject::connect<void(__cdecl QNetworkAccessManager::* )(QNetworkReply *),void(__cdecl faceEnterWindow::* )(QNetworkReply &)>(const QNetworkAccessManager *,Func1,const faceEnterWindow *,Func2 &&,Qt::ConnectionType)”的引用 with [ Func1=void (__cdecl QNetworkAccessManager::* )(QNetworkReply *), Func2=void (__cdecl faceEnterWindow::* )(QNetworkReply &) ]
最新发布
05-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值