开发者

will be this initialization syntax valid in upcoming c++0x standard?

开发者 https://www.devze.com 2023-01-07 05:32 出处:网络
Suppose we have following two classes: class Temp{ public: char a; char b; }; class Final{ private: int a; char b;

Suppose we have following two classes:

class Temp{
 public:
  char a;
  char b;
};
class Final{
 private:
  int a;
  char b;
  char c;
 public:
  Final(Temp in):b(in.a),c(in.b){}
  //rest of implementation
};
开发者_如何学编程

can we initialize an object of the Final class with following syntax in upcoming c++0x standard:

Final obj(Temp{'a','b'});


C++0x adds uniform initialization like for POD-struct and array types using braces ({}) for all types as well special initializer lists to support variable number of elements/arguments in them just like an array. So your example can be written as:

Final obj = { { 'a', 'b' } };

or

Final obj { { 'a','a' } };
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号