首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class test{ private: int a: public: test0{cout+”constructor”+en
有如下程序: #include using namespace std; class test{ private: int a: public: test0{cout+”constructor”+en
admin
2019-04-01
53
问题
有如下程序:
#include
using namespace std;
class test{
private:
int a:
public:
test0{cout+”constructor”+endl;}
test(int a){cout+a+endl;)
test(const test&test)
{
a=test.a:
cout+“copy constructor”+endl;
)
test(){Cout+”destructor”+endl;)
);
int main()
{
test A(3);
return 0:
}
运行时输出的结果是( )。
选项
A、3
B、constructor
destructor
C、copy constructor
destructor
D、3
destructor
答案
D
解析
此题考查的是构造函数和析构函数。一个类可以有多个构造函数,但只能有一个析构函数。每一个对象在被创建时,都会隐含调用众多构造函数中的一个,而在销毁时又会隐含调用唯一的析构函数。此题中,主函数创建对象A是会隐含调用test(int a)这个构造函数,输出3:接着主函数结束,对象A销毁又隐含调用~test()析构函数输出destructor。
转载请注明原文地址:https://kaotiyun.com/show/peAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下程序的输出结果是#include<iostream.h>voidmain(){charx=040;cout<<(X<<1);}
有以下程序#include<iostream>usingnamespacestd;longfib(intn){if(n>2)return(fib(n-1)+fib(n-2));
若有说明语句:chara[]="Itismine";char*p="Itismine";则以下不正确的叙述是
若执行下面的程序时,从键盘上输入5和2,则输出结果是#include<iostream.h>voidmain(){inta,b,k;cin>>a>>b;k=a;if(a<b
如果表达式x*y+z中,“*”是作为友元函数重载的,“+”是作为成员函数重载的,则该表达式还可为
下列程序的运行结果为______。#include<iostream.h>classmyclass{private:inta,b,c;public:voidfun()
结构化分析方法是面向______进行分析的方法。
类模板template<classT>classx{…},其中友元函数f对特定类型T(如int),使函数f(x<int>)成为x<int>模板类的友元,则其说明为()。
如下类定义中包含了构造函数和复制构造函数的原型声明,请在画线处填写正确的内容,使复制构造函数的声明完整。classmy(21ass{private:intdata:public::MyClass(int
在声明派生类时,如果不显示地给出继承方式,缺省的类继承方式是私有继承private。已知有如下类定义:classTestClass{protected:voidfun(){}};classTestClass1:
随机试题
感性认识的三种形式是()。
他习惯于晚睡晚起。
女,57岁,左鼻翼发现皮肤病损18个月。面积逐渐增大,反复出现破溃,就诊时检查:病损位于左鼻翼,约1cm×1cm,略高出皮肤,中央表浅溃疡,由表层黑褐色痂皮覆盖,腮腺区和颌下未及肿大淋巴结。最可能的诊断是
以下有关地西泮的说法不正确的是
A.呋塞米B.地高辛C.硝酸甘油D.扎莫特罗E.卡托普利
最常见的个人贷款营销渠道不包括()。
下列说法中,正确的是()。
[A]ThecontrolofthemixtureissoperfectthatwhereveryougointheworldwhereKFCissold,theendresultisexactlythe
设窗体名称为frmTest,为了在程序代码中将窗体的标题改为"等级考试",其代码应该是
BlackmarketforGunintheUSAsAmericansdigestthenewsofanothergunatrocity,amallshootinginNebraskaonDecember
最新回复
(
0
)