Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 带初始值设定项列表的字符串赋值 你能给我解释一下,为什么会有差异 什么是PKcE_C++_C++11_Initializer List - Fatal编程技术网

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
与N3922
auto 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