?????????????new???????????????б???????
????vector<int> *pv = new vector<int>{0?? 1?? 2?? 3?? 4};
????int *pi = new int[5]{0?? 1?? 2?? 3?? 4};
????cout<<"test new alloator using list initialization: "<<(*pv)[2]<<' '<<pi[2]<<endl;
????????????????/??????????????б???????
m1.insert({"d"?? "D"});
vector<string> error_msg(int typ)
{
switch(typ)
{
case 1:
return {"type1"?? "msg1"};
case 2:
return {"type2"?? "msg2"};
default:
return {};
}
}
pair<string?? string> get_pair(int typ)
{
if(typ == 1) return {"key"?? "value"};
return pair<string?? string>("default key"?? "default value");
}
vector<string> err_msg1 = error_msg(1);
vector<string> err_msg2 = error_msg(2);
vector<string> err_msg3 = error_msg(3);
cout<<"test return value list initialization: "<<err_msg1[1]<<' '<<err_msg2[1]<<' '<<err_msg3.empty()<<endl;
pair<string?? string> p1 = get_pair(1);
pair<string?? string> p2 = get_pair(2);
cout<<"test return pair list initialization: "<<p1.first<<' '<<p2.first<<endl;
???????????????
????C++11??????????????????????г????/?б???????
class InitClass
{
public:
void print_class()
{
cout<<field1<<' '<<field2<<' '<<field3<<' '<<field4<<endl;
}
private:
int field1 = 1;
int field2;
double field3 = 1.0;
double field4;
};
class InitClassMgr
{
public:
vector<InitClass> init_objs = {InitClass()};
};
InitClass test_class;
cout<<"test class member initialization: ";
test_class.print_class();
InitClassMgr mgr;
cout<<"test class member of class type initialization: ";
mgr.init_objs[0].print_class();
???????
????1??long long?????
????2??nullptr?????????????????
????3??constexpr????????????????
????4??noexcept????????????????????????????????????????????ж??????????????????????
????5????????????????????????new???????????б???????????????????????????????б???????
????6???????????????????г????/?б???????