单选题若有类T说明class T{inti;friend void fFriend(T,int);};,则函数fFriend的错误定义是()Avoid fFriend(T objT,int k){objT.i=k;}Bvoid fFriend(T objT,int k){k=objT.i;}Cvoid T::fFriend(T objT,int k){k+=objT.i;}Dvoid fFriend(T objT,int k){objT.i+=k;}

单选题
若有类T说明class T{inti;friend void fFriend(T&,int);};,则函数fFriend的错误定义是()
A

void fFriend(T &objT,int k){objT.i=k;}

B

void fFriend(T &objT,int k){k=objT.i;}

C

void T::fFriend(T &objT,int k){k+=objT.i;}

D

void fFriend(T &objT,int k){objT.i+=k;}


参考解析

解析: 暂无解析

相关考题:

下列程序段中,A_class的成员函数Variance()可求出两数的平方差,请改写该程序段,把Variance()函数从A_class类中分离出来,用友元函数来实现该函数的功能。class A_class {private:intx,y,t;public:A_class(int i,int j):x(i),y(j) {if(yx){t=x;x=y;y=t;}}intVariance(){return x*x-y*y;}//其它函数从略};void main() {A_classA_obj(3,5);coutResult:A_obj.Variance()endl;}

有如下类定义:class AA{int a;public:int getRef() const{return a;} // ①int getvalue() const{return a;} // ②void set(int n) const{a=n;} // ③friend void show(AA aa) const {cout // ④};其中的四个函数定义中正确的是A . ①B . ②C . ③D . ④

设有以下类的定义:class Ex{ int x;public:void setx(int t=0);};若在类外定义成员函数setx( ),以下定义形式中正确的是A.void setx(int t){…}B.void Ex::setx(int t){…}C.Ex::void setx(int t){…}D.void Ex::setx( ){…}

使用VC6打开考生文件夹下的工程test41_3。此工程包含一个test41_3.cpp,其中定义了类Rectangle,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。(1)定义类Rectangle的私有数据成员left,top和fight,bottom,它们都是int型的数据。请在注释“//**1**”之后添加适当的语句。(2)添加类Rectangle的带四个int型参数1、t、r、b的构造函数的声明,并使这四个参数的默认值均为0,请在注释“//**2**”之后添加适当的语句。(3)添加类Rectangle的成员函数SetTop()参数为int型的t,作用为把t的值赋给类的数据成员top,添加类Rectangle的成员函数SetBottom()参数为int型的t,作用为把t的值赋给类的数据成员bottom,请在注释“//**3**”之后添加适当的语句。(4)完成派生类Rectangle的成员函数Show()的定义,使其以格式“right-bottom point is(right,bottom)”输出,请在注释“//**4**”之后添加适当的语句。源程序文件test41_3.cpp清单如下:include <iostream.h>class Rectangle{// ** 1 **int right, bottom;public:// ** 2 **~ Rectangle(){};void Assign(int 1, int t, int r, int b);void SetLeft(int t){left = t;}void SetRight(int t){right = t;}// ** 3 **void SetBottom(int t){bottom = t;}void Show();};Rectangle::Rectangle(int 1, int t, int r, int b){left = 1; top = t;right = r; bottom = b;}void Rectangle::Assign(int 1, int t, int r, int b){left = 1; top = t;right = r; bottom = b;}void Rectangle::Show(){cout<<"left-top point is ("<<left<<","<<top<<")"<<'\n';// ** 4 **}void main(){Rectangle rect;rect.Show();rect.Assign(100,200,300,400);rect.Show();}

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】设计一个类模板SamPle用于对一个有序数组采用二分法查找元素下标。【C++程序】include < iostream. h >define Max 100 //最多元素个数template < class T >class Sample{T A[Max]: //存放有序数序int n: //实际元素个数publicSample( ) { } //默认构造函数Sample(T a[] ,int i); //初始化构造函数int seek(T c);void disp( ){for(int i=0;i <n;i ++)cout<<A[i] <<" ";cout<<endl:} } template < class T >Sample <T>: :Sample(T a[ ],int i){n=i:for( intj =0;j < i;j ++ )(1);}template < class T >int Sample < T >:: seek( T c){int low =0,high = n-1 ,mid;while((2)){mid = (low + high)/2;if((3))return mid;else if( (4) )low=mid+|;else(5);}return-1;}void main( ){char a[ ] ="acegkmpwxz";Sample < char > s(a, 1);cout<<"元素序列:" ;s. disp( );cout<<"元素'g'的下标:"<<s. seek('g') <<endl;}

为使下列程序的正确输出结果为: Now is 2004-7-6 12:12:12 那么应该在程序划线处填入的语句是( )。 #include <iostream> using namespace std; class TIME; class DATE { public: DATE(int y=2004,int m=1,int d=1) { year=y; month=m; day=d; } void DateTime(TIME t); private: int year,month, day; }; class TIME { public: TIME(int h=0,int m=0,int s=0) { hour=h; minute=m; second=s; } ______________; //将类 DATE 中成员函数 DateTime 声明为类 TIME 的友元函数 private: int hour,minute, second; }; void DATE: :DateTime(TIME t) { cout<<"Now is "<<year<<'-'<<month<<'-'<<day<< ' '<<t.hour<<":"<<t.minute<<': '<<t.seoond<<'.'<<end1; } int main ( ) { DATE d(2004,7,6); TIME t (12, 12, 12); d. DateTime (t); return 0; }A.friend void DateTime(TIME t);B.friend void DATE::DateTime(TIME 0;C.void DateTime(TIME t);D.friend void DateTime(TIME t);

有如下类定义: class AA { int a; public: int getRef()const{ return a; } //① int getValue()const{ return a; } //② void set(int n)const{ a=n; } //③ friend void show(AA aa)const{ cout<<a; } //④ }; 其中的四个函数定义中正确的是( )。A.①B.②C.③D.④

类clasg one在声明func成员函数时发生错误,出错原因是______。class oneprivate:int a;public:void func(two);};class two{private:int b;friend vold one::func(two);};void one::func(twor){a=r.b;}

下列程序中声明了两个类AA和BB,其中函数“print”是类AA的成员函数,但是类BB的友元函数。请在①、②和⑧处各填入正确的内容,使程序能正常运行。include<iostream.h>【 】;class AA{int t;public:AA(int x){t=x;}void print(BB b) ;};class BB{int s;public:BB(int y){s=y;}friend void 【 】 print(BB );};void 【 】{ cout<<"AA:"<<t<<"BB: "<<w.s<<end1;}<void main(){AA m(6);BB n(8);m.print(n);}输出结果为:AA:6;BB:8

阅读下列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);}}

下列函数中,具有隐含的this指针的是( )。void fun1(); //①class MyClass{public:friend void fun2(); //②static int fun3(); //③int fun4(); //④}; A. ①B.②C.③D.④

类模板templateclass x{...},其中,友元函数f对特定类型T(如int),使函数 f(x);成为 类模板template<class T>class x{...},其中,友元函数f对特定类型T(如int),使函数 f(x<int>);成为x<int>模板类的友元,则其说明为( )。A.friend void f();B.friend void f(x<T>);C.friend void A:: f()D.friend void C<D:: f(x<T>);

为了使程序的输出的正确结果为: Now is 2004.7.10 10:10:10. 那么应在下列程序划线处填入的正确语句是( )。 那么应在下列程序划线处填入的正确语句是( )。 #include <iostream> using namespace std; class TIME; class DATE { public: DATE(int y=2004,int m=1,int d=1) { year=y; month=m; day=d; } friend void DateTime(DATE d, TIME t); private: int year, month, day; }; class TIME { public: TIME(iht h=0, int m=0,int s=0) { hour=h; minute=m; second=s; } friend void DateTime(DATE d,TIME t); private: int hour,minute, second; }; ______________________ //函数 DateTime 的首部 { cout<<"Now is"<<d.year<<'.'<<d.month<<'.'<<d.day<< ' '<<t.hour<<":"<<t.minute<<':'<<t.second<<'.'<<end1; } int main ( ) { DATE d(2004,7,10); TIME t(10, 10, 10); DateTime(d,t); return 0; }A.void DateTime(DATE d,TIME t)B.void TIME::DateTime(DATE d,TIME t) constC.friend void DateTime(DATE d,TIME t)D.void DATE::DateTime(DATE d,TIME t)

已知有下列类的说明,则下列哪个语句是正确的?public class Test { private float f=1.0f; int m=12; static int n=1; public static void main(String arg[]) { Test t= new Test(); }}A.t.f;B.this. nC.Test.m;D.Test.f;

类模板templateclass x{…},其中,友元函数f对特定类型T(如int),使函数f(x=成 类模板template<class T>class x{…},其中,友元函数f对特定类型T(如int),使函数f(x<int>=成为x<int>模板类的友元,则其说明为( )。A.friend void f();B.friend void f(x<T>=;)C.friend void A::f()D.friend void C<T>::f(x<T>=;)

有如下类定义: class Test { private int x; public int y; public void setX (int m) {x=m;} public int getX( ) {return x;} }现用Test t=new Text();生成一个对象t,则如下语句中,错误的是( )。A.t.x=10;B.t.y=10;C.t. setX(10);D.int m=t.getX( );

类模板templateclass x{…},其中友元函数f对特定类型T(如int),使函数f(x)成为x 类模板template<class T>class x{…},其中友元函数f对特定类型T(如int),使函数f(x<int>)成为x<int>模板类的友元,则其说明为( )。A.friend voidf();B.friend voidf(x<T>);C.friend voidA::f();D.friend void C<T>::f(x<T>);

下列程序用于打印出ASCⅡ字符,其析构函数内的语句应为【 】。 include inelude 下列程序用于打印出ASCⅡ字符,其析构函数内的语句应为【 】。include<iostream. h>inelude<iomanip, h>template<class T>class Array{T * elems;int size;public:Array(int.s);~Array()T operator[](int)void perator=(T)};template<class T>Array<T>::Array(int s)size=s;elems=new T[size]for(int i=0;i<size;i++)elems[i]=0}template<celass T>Array<T>::~Array(){______template <class T>T Array<T>::operator[](int index){return elems[index];}template<class T>void Array<T>::operator=(T temp){for(int i=0;i<size;i++)elems[i]=temp;}void main(){int i,n=26;Array<int> arr1(n)Array<char> arr2(n)for(i=0;i<n;i++){ -.arr1[i]='a'+i;arr2[i]='a'+i;}cout<<"ASCII 字符"<<endl;for(i=0;i<n;i++)cout<<setw(8)<<arr1[i]<<setw(8)<<arr2[i]<<endl;}

有如下类定义: class AA { im a: public: int getRefconst{return&a;}//① int getValueconst{return a;}//② void set(int n)const{a=n;}//③ friend void show(AA aA.const{couta;}//④ }; 其中四个函数的定义中正确的是( )。A.①B.②C.③D.④

类模板templateclass x(…),其中,友元函数f成为从该类模板实例化的每个模板类的友元,则 类模板template<class T>class x(…),其中,友元函数f成为从该类模板实例化的每个模板类的友元,则其说明应为( )。A.friend void f();B.friend void f(x<T>)C.friend void A::f();D.friend void C<T>::f(x<T>):

类class one 在声明func 成员函数时发生错误,出错原因是【 】。Class one{private:int a;public:void func(two )};class two{private:int b;friend void one: :func(two );};void one: : func(two r)a=r.b;}

如下程序编译时发生错误,错误的原因是show函数实现语句错误,则正确的语句应该为______。include<iostream.h>class test{private:int hum;public:test(int);void show( );};test::test(int n){num=n;}test::show( ){cout<<num<<endl;}void main( ){test T(10):T.show( );}

若有类T说明class T{inti;friend void fFriend(T,int);};,则函数fFriend的错误定义是()A、void fFriend(T objT,int k){objT.i=k;}B、void fFriend(T objT,int k){k=objT.i;}C、void T::fFriend(T objT,int k){k+=objT.i;}D、void fFriend(T objT,int k){objT.i+=k;}

若有类Z说明class Z{staticint a;public:static void fStatic(Z);};int Z::a=0;Z objZ;,则函数fStatic中访问数据a错误的是()。A、void Z::fStatic(){obj Z.a=1;}B、void Z::fStatic(){a=1;}C、void Z::fStatic(){this-a=0;}D、void Z::fStatic(){Z::a=0;}

若有类W说明class W{int a;public:voidfConst(int)const;};,则函数fConst的正确定义是()A、void W::fConst(intk)const{k=a;}B、void W::fConst(intk)const{k=a++;}C、void W::fConst(intk)const{cina;}D、void W::fConst(intk)const{a=k;}

单选题若有类Z说明class Z{staticint a;public:static void fStatic(Z);};int Z::a=0;Z objZ;,则函数fStatic中访问数据a错误的是()。Avoid Z::fStatic(){obj Z.a=1;}Bvoid Z::fStatic(){a=1;}Cvoid Z::fStatic(){this-a=0;}Dvoid Z::fStatic(){Z::a=0;}

单选题已知主函数中通过如下语句序列实现对函数模板swap的调用:int a[10],b[10];swap(a,b,10);下列对函数模板swap的声明中,会导致上述语句序列发生编译错误的是(  )。Atemplatetypename Tvoid swap(T a[],T b[],int size);Btemplatetypename Tvoid swap(int size,T a[],T b[]);Ctemplatetypename T1,typename T2void swap(T1 a[],T2 b[],int size);Dtemplateclass T1,class T2void swap(T1 all,T2 b[],int size);