N610060099) 有如下程序: #include #include using namespace std; class MyBag{ public: My

admin2020-07-23  24

问题 N610060099) 有如下程序:
       #include
       #include
       using namespace std;
       class MyBag{
       public:
           MyBag(string br,string cr):brand(br),color(cr) { cout<<++count; }
           ~MyBag() { --count; }
           static int GetCount() { return count; }
       private:
           string brand,color;
           static int count;
       };
       int MyBag::count=0;
       int main() {
           MyBag one("CityLife","Gray"),two("Micky","Red");
           MyBag *ptr=new MyBag("Coach","Black");
           delete ptr;
           cout<           return 0;
       }
运行时的输出结果是

选项 A、2
B、3
C、1232
D、1233

答案C

解析 本题考查静态数据成员和构造函数和析构函数,题目中定义了三个对象,那么一次输出count值,即123,销毁ptr后,执行析构函数,count减1 ,count为2,所以选项C正确。
转载请注明原文地址:https://kaotiyun.com/show/gGyp777K
0

随机试题
最新回复(0)