gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:55:57 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com