c++ - 在编译时确定指针类型

标签 c++ templates visual-c++ visual-studio-2005

我正在尝试从传递给宏的指针中提取类类型。这是我目前所拥有的

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/

相关文章:

c++ - 如何选择带有类型参数的成员变量?

c++ - 一个函数可以同时接受迭代器和反向迭代器作为参数吗

c++ - 使用 char *argv[] 而不是 char* argv[] 之间有很大的原因/差异吗?

c++ - GetKeyboardState 一键延时

c++ - 模板化静态模板成员

c++ - 库损坏错误

visual-c++ - 默认情况下,如何使用 CMake 使 GTest 构建/MDd(而不是/MTd)?

c++ - 静态全局变量 V 静态全局类变量

c++ - 是否可以在没有 Visual Studio 的情况下使用 C++ 为 Windows 开发?

c++ - 为什么我不能在我的程序中声明一个字符串 : "string is undeclared identifier"