- #include <iostream>
- class ArrayTest
- {
- public:
- ArrayTest() { std::cout << "ArrayTest()" << std::endl; }
- ArrayTest(int n) { std::cout << "ArrayTest(int)" << std::endl; }
- };
- int main()
- {
- ArrayTest *a1 = new ArrayTest();
- ArrayTest *a2 = new ArrayTest(0);
- ArrayTest *a3 = new ArrayTest[3]{ArrayTest(0), ArrayTest(), ArrayTest(1)};
- delete a1;
- delete a2;
- delete[] a3;
- return 0;
- }
- 编译信息:
- array.cc:14: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
- 运行结果:
- ArrayTest()
- ArrayTest(int)
- ArrayTest(int)
- ArrayTest()
- ArrayTest(int)
- //该片段来自于http://www.codesnippet.cn/detail/080520133189.html
来源: http://www.codesnippet.cn/detail/080520133189.html