#includeiostreamusing namespace std;class Rectpublic Rect count++; ~Rect count--; static int getCount return count; private int width; int height;
原因是程序中没有定义矩形个数的规则,即没有给定矩形的数量,只有在矩形被创建或销毁时才会更新计数器,因此在程序中只有两个矩形,但计数器的值可能会出现错误。另外,程序中定义的矩形类没有实现任何功能,只有计数器,因此可以考虑添加一些实用的方法来完善它。
原文地址: https://www.cveoy.top/t/topic/b6QS 著作权归作者所有。请勿转载和采集!