c++mooc第六章小测
2021-05-11 11:30
标签:turn mes int use using ios fun print call (红色为补充代码) 001:看上去像多态#include
002:Fun和Do:
#include
B &p
) {
p.Fun(); p.Do();
}
int main() {
C c;
Call( c);
return 0;
}
003:这是什么鬼delete
#include using namespace std;
class A
{
public:
A() { }
//补充代码
virtual ~A(){
cout"destructor A";
}
};
class B:public A {
public:
~B() { cout "destructor B" ; }
};
int main()
{
A * pa;
pa = new B;
delete pa;
return 0;
}
004:怎么又是Fun和Do
#include using namespace std;
class A {
private:
int nVal;
public:
void Fun()
{ cout "A::Fun" ; };
virtual void Do()
{ cout "A::Do" ; }
};
class B:public A {
public:
virtual void Do()
{ cout "B::Do" ;}
};
class C:public B {
public:
void Do( )
{ cout "C::Do"; }
void Fun()
{ cout "C::Fun" ; }
};
void Call(
//补充代码
A*p
) {
p->Fun(); p->Do();
}
int main() {
Call( new A());
Call( new C());
return 0;
}
c++mooc第六章小测
标签:turn mes int use using ios fun print call
原文地址:https://www.cnblogs.com/gongsuiqing/p/13152628.html
上一篇:SpringBoot数据访问