C++ 带初始值设定项列表的字符串赋值 你能给我解释一下,为什么会有差异 什么是PKcE
代码:C++ 带初始值设定项列表的字符串赋值 你能给我解释一下,为什么会有差异 什么是PKcE,c++,c++11,initializer-list,C++,C++11,Initializer List,代码: 我不知道PKcE代表什么。我只能猜测P代表指针,K代表常量,c代表字符。不知道E代表什么。返回的名称依赖于编译器。至于你的问题(我认为),为什么类型推断的变量不能被推断为?在初始化中确实使用了一个std::initializer\u list。c++filt-t st16 initializer\u listIPKcE给出了std::initializer\u list与N3922auto S{“IDE}将被推断为常量字符*,以及自动C{string{“IDE”}将被推断为std::st
我不知道
PKcE
代表什么。我只能猜测P
代表指针,K
代表常量,c
代表字符。不知道E
代表什么。返回的名称依赖于编译器。至于你的问题(我认为),为什么类型推断的变量不能被推断为?在初始化中确实使用了一个std::initializer\u list
。c++filt-t st16 initializer\u listIPKcE
给出了std::initializer\u list
与N3922auto S{“IDE}代码>将被推断为常量字符*
,以及自动C{string{“IDE”}
将被推断为std::string
好的猜测,它们都是正确的。而I
…E
只是标记模板参数列表。
#include <iostream>
#include <typeinfo>
using namespace std;
int main() {
string s {"IDE"};
std::cout<<typeid(s).name()<<std::endl;
auto S{"IDE"}; // why do not deduced as string?
std::cout<<typeid(S).name()<<std::endl;
auto c = {"IDE"}; // why do not deduced as string?
std::cout<<typeid(c).name()<<std::endl;
auto C {string{"IDE"}}; // why do not deduced as string?
std::cout<<typeid(C).name()<<std::endl;
auto Z = string{"IDE"};
std::cout<<typeid(Z).name()<<std::endl;
}
Ss
St16initializer_listIPKcE
St16initializer_listIPKcE
St16initializer_listISsE
Ss
string s {"IDE"}; // Type of s is explicit - std::string
auto S{"IDE"}; // Type of S is an initializer list consisting of one char const*.
auto c = {"IDE"}; // Type of c is same as above.
auto C {string{"IDE"}}; // Type of C is an initializer list consisting of one std::string
auto Z = string{"IDE"}; // Type of Z is std::string