单项选择题

有如下程序: #include using namespace std; class XX{ int x; public: XX(int xx=0):x(xx){} int getX(){return x;} }; class YY:public XX{ int y; public: YY(int xx,int yy):x(xx),y(yy){} int getV(){return getX()+y;} }; int main(){ YY c(3,4); cout<
A.3
B.4
C.7
D.10

<上一题 目录 下一题>
热门 试题

单项选择题
在类中重载赋值运算符时,应将其声明为类的
A.静态函数
B.友元函数
C.成员函数
D.构造函数
单项选择题
有如下程序:#includeusing namespace std;class Boat;class Car{public:Car(int i):weight(i){ }friend int Total(const Car &c.const Boat &b); ①private:int weight;};class Boat{public:Boat(int i):weight(i){ }friend int Total(const Car &c,const Boat &b);private: int weight;};int Total(const Car &c,const Boat &b){ ②return c.weight+b.weight;}int main(){Car c(10);Boat b(8);cout<< The total weight is <<Total(c,b)<<endl; ③return 0;}下列关于程序的描述中,正确的是
A.程序编译正确
B.程序编译时语句①出错
C.程序编译时语句②出错
D.程序编译时语句③出错
相关试题
  • 已知类MyClock中未显式定义构造函数,并重...
  • 有如下类定义:class Animal{public:vir...
  • 有如下程序:#includeusing namespace s...
  • 有如下程序:#includeusing namespace s...
  • 有如下程序:#includeusing namespace s...