C++ 获取指针类型指向的类型

C++ 获取指针类型指向的类型,c++,templates,C++,Templates,我想创建一个包含类型typedef的helper结构,该模板指针参数指向: template<class T*> struct pointer_lower_level { typedef typename T type_pointed; }; 对我来说,这看起来像是法律语法,但我有很长的一天,所以我可能是错的。你需要一个模板专门化: // first declare the general template... template<class T> struct

我想创建一个包含类型typedef的helper结构,该模板指针参数指向:

template<class T*>
struct pointer_lower_level
{
    typedef typename T type_pointed;
};

对我来说,这看起来像是法律语法,但我有很长的一天,所以我可能是错的。

你需要一个模板专门化:

// first declare the general template...
template<class T>
struct pointer_lower_level;

// ...then provide a partial specialization for pointers
template<class T>
struct pointer_lower_level<T*>
// note this... ----------^^^^
{
    typedef T type_pointed;
};
//首先声明常规模板。。。
模板
结构指针\u较低\u级别;
//…然后为指针提供部分专用化
模板
结构指针\u较低\u级别
//请注意----------^^^^
{
typedef T type_尖;
};

假设您不想使用,我认为您想要的是使用一个

模板
结构指针\u较低\u级别;
模板
结构指针\u较低\u级别{
使用类型_=T;
};

我不知道您为什么要实现自己的,所以如果是这样,您可以使用它,仅供参考:。
// first declare the general template...
template<class T>
struct pointer_lower_level;

// ...then provide a partial specialization for pointers
template<class T>
struct pointer_lower_level<T*>
// note this... ----------^^^^
{
    typedef T type_pointed;
};
template <typename>
struct pointer_lower_level;

template <typename T>
struct pointer_lower_level<T*> {
    using type_pointed = T;
};