【发布时间】:2018-11-01 10:18:37
【问题描述】:
我在下面的代码 sn-p 中声明了一个名为 pval 的变量,该变量试图在 T* [与 T 为 int ] 上派生 T&&。根据类型信息 [使用 abi 解码],派生的类型是 int*。
但是当我将int* 类型与decltype(pval) 进行比较时,它返回零而不是1,这意味着它将pval 视为与int* 不同的类型。那么typeid 或is_same 报告的int* 是错误的pval 是int*,这表明比较为假。
#include<iostream>
#include<string>
#include<typeinfo>
#include<cxxabi.h>
#include<type_traits>
using namespace std;
std::string classname(const std::type_info& info)
{
int status;
char* rslt=abi::__cxa_demangle(info.name(),0,0,&status);
std::string result(rslt);
free(rslt);
return result;
}
int main(int argc, char* argv[])
{
int* ptr = new int(10);
decltype(std::move(ptr)) pval = std::move(ptr);
cout << classname(typeid(pval)) << endl; // as per typeid information the type of pval is int*.
bool isSame = is_same<decltype(pval), int*>::value; // What then is the pval not same as int* as per is_same ?
cout << "isSame status = " << isSame << endl;
cout << is_same<int*, int*>::value << endl;
return(0);
}
【问题讨论】:
-
抱歉错过了,以后会继续的
-
谢谢burnabyRails :),我现在已经用对我有帮助的正确/最准确的答案标记了我所有的问题。
-
很高兴看到你有。您已经获得了一些代表和学者徽章!以防万一,没有必要过度。接受的答案应该基本上可以解决您的问题。无论如何,这是你的电话。我很快就会在这里删除我所有的 cmets。
-
是的,大部分答案都解决了我的问题。是的,我得到了更多的积分和声望谢谢!!享受我的帽子..... :)
标签: c++ c++11 decltype typeid value-categories