Bug in the tutorial?

I'm learning C++ by following the tutorials and testing the code in MS Visual Studio 2013. The following codes that are at the end of the Classes (I) section has error:

In particular, it's this line:
baz = new Rectangle { {2,5}, {3,6} };
It seems that this could mean:
1. Pass an array with two components {2,5} and {3,6} into the Constructor
2. Call the constructor with one variable {x,y} with x={2,5} and y={3,6}

Could someone shed some light on this?

Thanks,
Yang

// pointer to classes example
#include <iostream>
using namespace std;

class Rectangle {
int width, height;
public:
Rectangle(int x, int y) : width(x), height(y) {}
int area(void) { return width * height; }
};


int main() {
Rectangle obj (3, 4);
Rectangle * foo, * bar, * baz;
foo = &obj;
bar = new Rectangle (5, 6);
baz = new Rectangle { {2,5}, {3,6} };
cout << "obj's area: " << obj.area() << '\n';
cout << "*foo's area: " << foo->area() << '\n';
cout << "*bar's area: " << bar->area() << '\n';
cout << "baz[0]'s area:" << baz[0].area() << '\n';
cout << "baz[1]'s area:" << baz[1].area() << '\n';
delete bar;
delete[] baz;
return 0;
}
From the context, I think they meant this:
baz = new Rectangle[2] {{2, 5}, {3, 6}};
Thank you NT3 it worked! :) This makes sense too.
Topic archived. No new replies allowed.