An interesting point. As soon as I looked through the code and tried to convince the programmers to fix the new [], remove the inconsistency. I argued myself as "Element 5" from Effective C ++ by Scott Meyers. However, they argued with the words: "What you want, it works well!" and proved that there was no memory leak. However, it only worked with POD types. It looks like MS is trying to fix the inconsistency, as indicated by Raveline.
What happens if you add a destructor?
#include <iostream> class CBlah { static int instCnt; public: CBlah() : m_i(0) {++instCnt;} ~CBlah() { std::cout <<"d-tor on "<< instCnt <<" instance."<<std::endl; --instCnt; } private: int m_i; }; int CBlah::instCnt=0; int main() { //for(;;) { CBlah * p = new CBlah[10]; // with [] delete p; // no [] } return 0; }
No matter how stupid the “intellect” correction is added to VS, the code is not portable.
source share