class Rectangle {
int width, height;
public:
Rectangle(int x, int y) : width(x), height(y) {}
int area(void) { return width * height; }
};
int main() {
Rectangle * baz;
baz = new Rectangle { {2,5}, {3,6} };
delete[] baz;
return 0;
}
Gives error (g++ first.cpp)
first.cpp: In function ‘int main()’:
first.cpp:14:38: error: no matching function for call to ‘Rectangle::Rectangle(<brace-enclosed initialiser list>)’
The compiler is probably trying to use uniform initialization. Your constructor only takes two integers, but you are passing two pairs of two integers, so it doesn't match the signature of the constructor you declared.
Also, why are you using array delete without array new? I assume that you were trying to make an array of rectangle by passing those two pairs of ints, but that is not how it works.
Try this for one rectangle:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Rectangle
{
int width, height;
public:
Rectangle(int x, int y) : width(x), height(y) {}
int area(void) { return width * height; }
};
int main()
{
Rectangle * baz;
baz = new Rectangle {2,5};
delete baz;
return 0;
}