我正在尝试从传递给宏的指针中提取类类型。这是我目前所拥有的
template <class CLASS> class getter
{
public:
typedef CLASS type;
};
template <class CLASS> getter<CLASS> func(const CLASS* const)
{
return getter<CLASS>();
}
...
#define GETTYPE(PTR) func(p)::type
...
MyClass *p = new MyClass;
...
GETTYPE(p) myClass;
这可能吗?我是不是找错树了?
最佳答案
您可以在 C++11 中使用 decltype
。
关于c++ - 在编译时确定指针类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11216436/