有如下程序: #include<iostream> using namespace std; class Boat; class Car{ public: Car(int i):weight(i){}

admin2017-11-28  16

问题 有如下程序:
    #include<iostream>
    using namespace std;
    class Boat;
    class Car{
    public:
    Car(int i):weight(i){}
    Mend int Total(const Car&c,const Boat&b);//①
    private:
    int weight;
    };
    class Boat{
    public:
    Boat(int i):weight(i){}
  Mend 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、程序编译时语句③出错

答案A

解析 程序中定义了类Car和类Boat,在两个类中分别定义他们的构造函数和友元函数friend。程序在VC6.0中编译通过。
转载请注明原文地址:https://kaotiyun.com/show/b3Ap777K
0

最新回复(0)