早教吧作业答案频道 -->其他-->
对如下基类和派生类的声明,指出下列每个例子的错误(6分)classBase{voidfoo(int);private:intbar;doublefoobar;};classDerived:publicBase{voidfoo(string);boolbar(Base*pb);voidfoobar();private:stringbar;};(1
题目详情
对如下基类和派生类的声明,指出下列每个例子的错误(6分)
class Base{
void foo(int);
private:
int bar;
double foo_bar;
};
class Derived:public Base{
void foo(string);
bool bar(Base *pb);
void foobar();
private:
string bar;
};
(1)Derived d; d.foo(1034);
(2)bool Derived::bar(Base *pb){return foo_bar == pb->foo_bar;}
class Base{
void foo(int);
private:
int bar;
double foo_bar;
};
class Derived:public Base{
void foo(string);
bool bar(Base *pb);
void foobar();
private:
string bar;
};
(1)Derived d; d.foo(1034);
(2)bool Derived::bar(Base *pb){return foo_bar == pb->foo_bar;}
▼优质解答
答案和解析
(1)Derived d; d.foo(1034); //1034是int类型的数据,而Derived 类的foo函数数据类型为string
(2)bool Derived::bar(Base *pb){return foo_bar == pb->foo_bar;} //pb是Base类,而Base类中pb->foo_bar的这个成员是私有的,在Derived类的bar函数中显然无法调用。
(2)bool Derived::bar(Base *pb){return foo_bar == pb->foo_bar;} //pb是Base类,而Base类中pb->foo_bar的这个成员是私有的,在Derived类的bar函数中显然无法调用。
看了 对如下基类和派生类的声明,指...的网友还看了以下:
对如下基类和派生类的声明,指出下列每个例子的错误(6分)classBase{voidfoo(int 2020-08-04 …