#include <iostream>
class Object
{
public:
Object(void){ static unsigned counter = 0; number = counter++; }
~Object(void){ std::cout << number << " has been destroyed!" << std::endl; }
private:
unsigned number;
};
int main()
{
Object *obj = new Object[100];
delete[50] obj;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgT2JqZWN0CnsKCXB1YmxpYzoKCSAgICBPYmplY3Qodm9pZCl7IHN0YXRpYyB1bnNpZ25lZCBjb3VudGVyID0gMDsgbnVtYmVyID0gY291bnRlcisrOyB9CgkgICAgfk9iamVjdCh2b2lkKXsgc3RkOjpjb3V0IDw8IG51bWJlciA8PCAiIGhhcyBiZWVuIGRlc3Ryb3llZCEiIDw8IHN0ZDo6ZW5kbDsgfQoJICAgIAoJcHJpdmF0ZToKCQl1bnNpZ25lZCBudW1iZXI7Cn07CgppbnQgbWFpbigpCnsKCU9iamVjdCAqb2JqID0gbmV3IE9iamVjdFsxMDBdOwoJZGVsZXRlWzUwXSBvYmo7CglyZXR1cm4gMDsKfQ==
prog.cpp: In function ‘int main()’:
prog.cpp:16:9: error: expected ‘]’ before numeric constant
delete[50] obj;
^
prog.cpp:16:9: error: type ‘int’ argument given to ‘delete’, expected pointer
prog.cpp:16:11: error: expected ‘;’ before ‘]’ token
delete[50] obj;
^
prog.cpp:15:10: warning: unused variable ‘obj’ [-Wunused-variable]
Object *obj = new Object[100];
^