有如下程序: #include using namespace Std; class test{ private: int a; public: test(){cout

admin2017-12-14  29

问题 有如下程序:
    #include
    using namespace Std;
    class test{
    private:
    int a;
    public:
    test(){cout<<"constructor"<    test(int a){cout<    test(const test &_test){
    a=test.a;
    cout<<"copy constructor"<    }
    ~test(){cout<<"destructor"<    }  ;
    int main(){
    test A(3);
    return 0;
    }
    执行这个程序的输出结果是(    )。

选项 A、3
B、constructor
destructor
C、copy constructor
destructor
D、3
destructor

答案D

解析 本题考查默认构造函数和带参数的构造函数以及析构函数,本题中定义了一个对象A(3),对象带着参数,所以执行带参数的构造函数,输出3,然后执行析构函数,输出destructor。所以本题答案为D。
转载请注明原文地址:https://kaotiyun.com/show/HkAp777K
0

随机试题
最新回复(0)