【发布时间】:2020-12-06 15:10:08
【问题描述】:
我有以下结构,其中有许多具有不同的“输入”和“输出”类型。
#include <string>
template <>
struct Corresponding<const char*> {
using CorrespondingT = std::string;
};
这会导致错误:
explicit specialization of non-template struct
'Corresponding'
template <> struct Corresponding<const char*> { using Correspond...
这应该可以用作Corresponding<T>::CorrespondingT,在这种情况下,T 可以是const char*,但也可以是其他类型,例如添加更多类型,例如
template <>
struct Corresponding<int> {
using CorrespondingT = boost::multiprecision::cpp_int;
};
然后
template <typename T> using GetCorresponding = typename Corresponding<T>::CorrespondingT;
让我相信这会奏效的来源:https://en.cppreference.com/w/cpp/utility/hash、https://en.cppreference.com/w/cpp/types/remove_reference。
还有其他问题与此相同的错误,但他们似乎在尝试不同的事情,使它们在这里不相关。
我正在使用 gnu++2a。
【问题讨论】:
标签: c++ templates struct template-specialization