when using a trailing return type in C++ template function, the function call in decltype with template parameter as follows will compile successfully.
// case 1: no error
template <typename T>
struct basic_type { using type = T; };
template<typename T>
auto getBox1() -> decltype((getBox(basic_type<T>{})))
{
return getBox(basic_type<T>{});
}
if the parameter of function getBox
is void, a gramma error would assert immediately.
// case 2: error
template <typename T>
struct basic_type { using type = T; };
template<typename T>
auto getBox1() -> decltype((getBox())) // ERROR TIPS, "identifier "getBox" is undefined"
{
return getBox();
}
since getBox
function is not declared or defined either case, why case 1 is OK but case 2 would give an error?
Any explanation would be great appreciated.
googled this problem, but the seach engine could even not parse the content.
Aucun commentaire:
Enregistrer un commentaire