关于下面类,叙述正确的是____ class A { public: A() { p=this; } ~A() { if(p!=NULL) { delete p; p=NULL; } } A* p; };A.其应用能正常结束B.其应用会无限递归C.类中不能包含成员指针 A* pD.类成员定义中不能包含指向自身的指针

关于下面类,叙述正确的是____ class A { public: A() { p=this; } ~A() { if(p!=NULL) { delete p; p=NULL; } } A* p; };

A.其应用能正常结束

B.其应用会无限递归

C.类中不能包含成员指针 A* p

D.类成员定义中不能包含指向自身的指针


参考答案和解析
在类中,不作特别说明的数据成员均为私有类型

相关考题:

有以下程序#include stdio.hmain( ){ int n,*p=NULL;*p=n;printf("Input n:"); scanf("%d",p); printf("output n:"); printf("%d\n",p);}该程序试图通过指针 p 为变量 n 读入数据并输出,但程序有多处错误,以下语句正确的是A)int n,*p=NULL;B)*p=n;C)scanf("%d",p)D)printf("%d\n",p);

下面程序实现十进制向其他进制的转换。[Java程序]C1ass Node{int data;Node next;}class Transform{private Node top;publiC void print(){Node P;while(top !=null){P=top;if(P.data>9)System.out.print((char)(p.data+55));elseSystem.out.print(p.data);top=P.next;}}public void Trans(int d,int i)(//d为数字;i为进制int m;(1) n=false;Node P;while(d>0){(2) ;d=d/i;P=flew Node();if( (3) ){P.data=m;(4) ;top=P;n=true;}else{p.data=m;(5) ;toP=P;}}}}

有如下类定义,请将Sample类的复制构造函数补充完整。class Sample{public:Sample( ){ }~Sample( ){if(P)delete P;)Sample(const Samples){______}void SetData(int datA) {P=new int(datA) ;}private:int*P:};

有以下程序 include main() { int n,*p=NULL; *p=n; printf(" 有以下程序 #include <stdio.h> main() { int n,*p=NULL; *p=n; printf("Input n:");scanf("%d",p);printf("output n:");printf("%d\n",p); } 该程序试图通过指针p为变量n读入数据并输出,但程序有多处错误,以下语句正确的是A.int n,*p=NULL;B.*p=n;C.scanf("%d",p)D.printf("%d\n",p);

有以下程序:inlucdemain()D)2 3 3{int n,*P=NULL;*p=printf("input n:");scanf("%d 有以下程序: #inlucde<stdio.h> main()D)2 3 3 {int n,*P=NULL; *p=&n; printf("input n:");scanf("%d",&p);printf("output n:");printf("%d\n",p); } 该程序试图通过指针P为变量n读入数据并输出,但程序有多处错误,以下语句正确的是( )。A.int n,*P=NULL;B.*P=&n;C.scanf(“%d",&p)D.printf("%d\n",p);

下面程序运行时输出结果为______。 include include class Rect { public: Rect(int 下面程序运行时输出结果为______。include<iostream.h>includeclass Rect{public:Rect(int l, int w){length=l; width=w;)void Print(){cout<<"Area:"<<length*width<<end1;}void operator delete(void*p){free(p);}private:int length, width;};void main(){Rect *p;p=new Rect(5, 4);p->Print();delete p;}

p指向线性链表中某一结点,则在线性链表的表尾插入结点s的语句序列是()。A.while(p->next!=NULL)p=p->next;p->next=s;s->next=NULL;B.while(p!=NULL)p=p->next;p->next=s;s->next=NULL;C.while(p->next!=NULL)p=p->next;s->next=p;p->next=NULL;D.while(p!=NULL)p=p->next->next;p->next=s;s->next=p->next;

阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】设单链表的结点类和链表类的定义如下,链表不带有表头结点。请填空:include<iostream.h>include<assert.h>template<class T>class List;template<class T>class ListNOde{friend (1);private:T data;ListNode<T> *link;public:ListNode():link(NULL)()ListNOde(const T item,ListNOde<T>*next=NULL):data(item),link(next){}};template<class T>class List{private:ListNode<T>*first;void createList(T A[],int n,int i,ListNOde<T>*p);void printList(ListNOde<T>*p);public:List();~List();friend ostream operator<<(ostream ost,List<T>L);friend istream operator>>(istream ist,List<T>L);};template<class T>istream operator>>(istream ist,List<T>1){int i,n; ist>>n;T A[n];for(i=0;i<n;i++) (2);createList(A,n,0,first);}template<class T>void List<T>::createList(TA[],int n,int i,ListNOde<T>* p){//私有函数:递归调用建立单链表if(i==n)p=NULL;else{p=new ListNode<T>(A[i]);assert(p !=NULL);createList((3));}}template<class T>ostream operator<<(ostream ost,List<T> L){(4);}template<class T>void List<T>::printList(ostream ost,ListNode<T>*p){if(p!=NULL){ost<<p->data;(5);}}

下面程序运行时输出结果为【】。 include include class Rect { public: Rec 下面程序运行时输出结果为【 】。include<iostream.h>include<malloc.h>class Rect{public:Rect(int1,int w)(length=1;width=w;)void Print(){cout<<"Area:"<<length *width<<endl;)void *operator new(size-t size){return malloc(size);}void operator delete(void *p){free(p)private:int length,width;};void main(){Rect*p;p=new Rect(5,4);p->Print();delete p;}

非空循环单链表(head为头指针)的尾结点(由指针p所指示)应满足()。 A.p->next==NULL;B.p==NULL;C.p->next==head;D.p==head;

非空的循环单链表head的尾结点(由p所指向)满足A.p-next==NULL B.p==NULL C.p-next=head D.p=head

对于下面程序,对p进行赋值正确的是( )。 class A{ public:fun(int i){cout<<i<<endl;} }; main(){ void(A::*p)(int); }A.p=fun;B.p=fun();C.p=A::fun;D.p=A::fun()

阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内。[说明]下面程序实现十进制向其它进制的转换。[Java程序]ClasS Node{int data;Node next;}class Transform{private Node top;public void print(){Node p;while(top!=null){P=top;if(P.data>9)System.out.print((char)(P.data+55));elseSystem.out.print(p.data);top=p.next;}}public void Trans(int d,int i){//d为数字;i为进制int m;(1) n=false;Node p;while(d>0){(2);d=d/i;p=new Node();if( (3) ){p.data=m;(4);top=P;n=true;}else{p.data=m;(5);top=P;}}}}

非空的循环单链表head的尾结点(由p所指向)应该满足A.p->next==NULL B.p==NULL C.p->next=head D.p=head

有如下类定义,请将Sample类的拷贝构造函数补充完整。class Sample{public:Sample(){)~Sample(){if(p)delete p;)Sample(const Sample s){______}void SetData(int data) {p=new int(data);}private:int*p;};

设有定义:int x=o,* P;,立刻执行以下语句,正确的语句是( )。A.p=x;B.* p=x;C.p=NULL;D.* p=NULL;

阅读以下说明和c++代码,将应填入(n)处的字句写在对应栏内。【说明】本程序将两个从小到大的有序链表合成一个新的从小到大的有序链表。链表的每一项由类 Node描述,而链表由List描述,类List的成员函数有以下几个:creatList(): 创建从小到大的有序链表。multiplyList(List L1, Llst L2): 将链表L1和链表L2合并。print(): 打印链表。【C++代码】include <iostream>using namespace std;class List;class Node{friend class List;public:Node(int data){(1);}private:int data;Node *next;};class List{public:List(){list=NULL;}void multiplyList(List L1, List L2);void creatList();void print();private:Node *list;};void List::creatList(){Node *p, *u, *pre;int dara;list=NULL;wbile(1){cout<<"输入链表的一项: (小于零,结束链表) "<<endl;cin>>data;if(dara<0)break;//小于零,结束输入p=list;while(p !=NULL dara>p->data){//查找插入点pre=p;p=p->next;}u=(2);if(p==list)list=u;else pre->next=u;(3);}}void List::multiplyList(List L1, List L2){Node *pL1, *pL2, *pL, *u;list = NULL;pL1 = L1.list;pL2 = L2.11st;while(pL1 != NULL pL2 != NULL){if(pL1->data < pL2->data){u = new Node(pL1->data);pL1 = pL1->next;}else{u = new Node(pL2->data);pL2 = pL2->next;}if(list == NULL){list =(4);}else{pL->next=u;pL=u;}}pL1 = (pL1 != NULL)? pL1:pL2;while(pL1 != NULL){u=(5);pL1 = pL1->next;if(list == NULL){list=pL=u;}else{pL->next=u;pL=u;}}}void List::print(){Node *p;p = list;while(p !=NULL){cout<<p->data<<"\t";p=p->next;&

If possible please suggest further improvement of the String class.Question 3:Given a link list, detect whether it's circular using only one loop.Tips: Below implementation is allowedfor( ... ){...}The following implementations is NOT allowed...for( ... ){...for( ... ) {...}}...or...for( p = list-head, q = list-head; p != NULL q != NULL; p = p-next ){...}...for( ... ){...}

class A{void P1(){cout"A111"};void P2(){cout"A222"};};class B:public A{void P1(){cout"B111"};virtual void P2(){cout"B222"};}..........A*cl=NULL;cl=new A;A-P1();A-P2();delete cl;cl=NULL;cl=new B;A-P1();A-P2();delete cl;cl=NULL;..........写出运行结果;

设变量P是指针变量,语句P=NULL;是给指针变量赋NULL值,它等价于( )。A.p="";B.p="0";C.p=0;D.p=";

设P是指针变量,语句P=NULL;等价于A.P=′0′;B.P=";C.P="";D.P=0;

下面程序的运行结果是()。includeusing namespace std;class A{public: virtual~A() { 下面程序的运行结果是( )。 #include<iostream> using namespace std; class A { public: virtual~A() { cout<<"call A::~A()"<<endl;} }; class B:public A { char * p; public: B(int i) { p=new char[i];} ~B() { delete(p); cout<<"call B::~B()"; } }; void main() { A * a=new B(8); delete a; }A.call B::~B()call A::~A()B.call B::~B()C.call A::~A()D.call A::~A()call B::~B()

非空的单循环链表L的尾结点P↑,满足( )A.P↑.next=NULL;B.P=NULL;C.P↑.next=L;D.P=L

写出下面算法的功能。voidfunction(Bitree*t){if(p!=NULL){function(p-lchild);function(p-rchild);printf(“%d”,p-data);}}

设变量p是指针变量,语句p=NULL;,是给指针变量赋NULL值,它等价于()A、p="";B、p=’0’;C、p=0;D、p=’’;

char*p与“空值”比较的if语句,以下写法()是正确的。A、if(p==NULL)B、if(p==0)C、if(p!=0)D、if(p)

单选题设有定义:int x=0,*p;紧接着的赋值语句正确的是(  )。A*p=x;B*p=NULL;Cp=x;Dp=NULL;

填空题写出下面算法的功能。voidfunction(Bitree*t){if(p!=NULL){function(p-lchild);function(p-rchild);printf(“%d”,p-data);}}