/*
虚函数表达:virtual <类型><函数名>(<参数表>);
*/
#include<iostream>
using namespace std;
// 基类 base
class Base{
public:
//虚函数
virtual void display() {
cout<<"Base::display()\n";
}
//纯虚函数
virtual void hide()=0;
};
/*
虚函数表达:virtual <类型><函数名>(<参数表>);
*/
#include<iostream>
using namespace std;
class Base {
public:
int base_i;
virtual void display(){
cout<<"Base:display\n";
}
//纯虚函数
virtual void pureFunc()=0;
void nomalFunc();
};
class Derived:public Base{
public:
int derived_j;
void display(){
cout<<"Derived:display\n";
}
};
int main(){
Base *ptr = new Derived();
ptr->display();
}
Derived d;
d.Base1::a=3;
d.Base1::display();
class Base{xxx};
class Base1:virtual Base{xxx}
class Base2:virtual Base{xxx}
class Derived:public Base1,public Base2{xxx}
//test02
#include <iostream>
using namespace std;
class MyTestB{
public:
MyTestB(){};
};
class MyTestA{
public:
MyTestB b;
};
int main(int argc)
{
MyTestA a;
cout<<"hello";
return 0;
}
class MyTestB{
public:
MyTestB(){};
};
class MyTestA:public MyTestB{};
int main(int argc)
{
MyTestA a;
cout<<"hello";
return 0;
}
#include <iostream>
using namespace std;
class MyTestA{
public:
virtual void DisPlay();
};
int main(int argc)
{
MyTestA a;
cout<<"hello";
return 0;
}
#include <iostream>
using namespace std;
class MyTestD{};
class MyTestC:virtual public MyTestD{};
class MyTestB:virtual public MyTestD{};
class MyTestA:public MyTestC,public MyTestB{};
int main(int argc)
{
MyTestA a;
cout<<"hello";
return 0;
}
网友评论