问题 单项选择题

若有以下程序:
#include <iostream>
using namespace std;
class Base

int x;
protected:
int y;
public:
int z;
void setx(int i)

x=i;

int getx ( )

return x;

;
class Inherit : private Base

private:
int m;
public:
int p;
void setvalue(int a,int b,int c, int d)

setx(

A.;
&n

答案

参考答案:A

解析: 本题中,基类Base中的保护成员y和公有成员setx和getx,经过私有继承以后,称为派生类Inherit的私有成员,所以可以在派生类Inherit的函数成员中对它们进行访问。类Inherit中的函数成员setvalue和display都是公有成员,所以可以通过Inherit的对象对它们进行访问。本程序的功能是对类中各数据成员进行赋值,然后查看赋值是否正确。

选择题
填空题