C++11 C++;具有自动声明链的类型推断

C++11 C++;具有自动声明链的类型推断,c++11,reference,type-conversion,auto,C++11,Reference,Type Conversion,Auto,我有一个练习: autop=42; 自动常数&q=p; 自动r=q; 自动&s=q; r和s的类型是什么 这是我的答案,但我不是很确定: auto p=42;//int 自动常数&q=p;//常数整数& 自动r=q;//int& 自动&s=q;//int&& 我找到了一种确定这些变量类型及其限定符(const或&)的方法: 从这篇文章 霍华德·希南特的回答是: C++11解决方案 我正在为非MSVC平台使用_cxa_demangle,正如ipapadop在其对demangle类型的回答中所建议

我有一个练习:

autop=42;
自动常数&q=p;
自动r=q;
自动&s=q;
rs的类型是什么

这是我的答案,但我不是很确定:

auto p=42;//int
自动常数&q=p;//常数整数&
自动r=q;//int&
自动&s=q;//int&&

我找到了一种确定这些变量类型及其限定符(const或&)的方法:

从这篇文章

霍华德·希南特的回答是:

C++11解决方案 我正在为非MSVC平台使用_cxa_demangle,正如ipapadop在其对demangle类型的回答中所建议的那样。但在MSVC上,我相信typeid可以定义名称(未经测试)。这个核心围绕着一些简单的测试,这些测试检测、恢复和报告cv限定符和对输入类型的引用

#包括
#包括
#ifndef\u理学硕士
#包括
#恩迪夫
#包括
#包括
#包括
模板
字符串
键入_name()
{
typedef typename std::remove_reference::type TR;
标准::唯一的
(
#ifndef\u理学硕士
abi::_cxa_demangle(typeid(TR).name(),nullptr,
空PTR,空PTR),
#否则
nullptr,
#恩迪夫
免费
);
std::string r=own!=nullptr?own.get():typeid(TR.name();
if(std::is_const::value)
r+=“常数”;
if(std::is_volatile::value)
r+=“挥发性”;
if(std::is_lvalue_reference::value)
r+=“&”;
else if(std::is\u rvalue\u reference::value)
r+=“&&”;
返回r;
}
(完)

因此,在主要功能方面:

intmain()
{
自动p=42;
自动常数&q=p;
自动r=q;
自动&s=q;

我找到了一种确定这些变量类型及其限定符(const或&)的方法:

从这篇文章

霍华德·希南特的回答是:

C++11解决方案 我在非MSVC平台上使用uuu cxa_demangle,正如ipapadop在回答demangle类型时所建议的那样。但在MSVC上,我相信typeid是demangle名称(未测试)。这个核心围绕着一些简单的测试,检测、恢复和报告cv限定符和对输入类型的引用

#包括
#包括
#ifndef\u理学硕士
#包括
#恩迪夫
#包括
#包括
#包括
模板
字符串
键入_name()
{
typedef typename std::remove_reference::type TR;
标准::唯一的
(
#ifndef\u理学硕士
abi::_cxa_demangle(typeid(TR).name(),nullptr,
空PTR,空PTR),
#否则
nullptr,
#恩迪夫
免费
);
std::string r=own!=nullptr?own.get():typeid(TR.name();
if(std::is_const::value)
r+=“常数”;
if(std::is_volatile::value)
r+=“挥发性”;
if(std::is_lvalue_reference::value)
r+=“&”;
else if(std::is\u rvalue\u reference::value)
r+=“&&”;
返回r;
}
(完)

因此,在主要功能方面:

intmain()
{
自动p=42;
自动常数&q=p;
自动r=q;
自动&s=q;
库特
decltype(p) is int
decltype(q) is int const&
decltype(r) is int
decltype(s) is int const&