打卡一小时
#include<iostream>
#include<cmath>
#include"Rectangle.h"
using namespace std;
int main()
{
Rectangle rect;
rect.intiRectangle(2, 3, 20, 10);
rect.move(3, 2);
cout << "The date of rect(x,y,w,h):" << endl;
cout << rect.getX() << "," << rect.getY() << "," << rect.getW() << "," << rect.getH() << endl;
return 0;
}
#include<iostream>
using namespace std;
class Base1
{
public:
void display()const
{
cout << "Base1::display()" << endl;
}
};
class Base2:public Base1
{
public:
void display()const
{
cout << "Base2::display()" << endl;
}
};
class Derived :public Base2
{
public:
void display()const
{
cout << "Derived::display()" << endl;
}
};
void fun(Base1 *ptr)
{
ptr->display();
}
int main()
{
Base1 base1;
Base2 base2;
Derived derived;
fun(&base1);
fun(&base2);
fun(&derived);
return 0;
}
#include<iostream>
using namespace std;
class Base1
{
public:
int var;
void fun()
{
cout << "Member of Base1" << endl;
}
};
class Base2
{
public:
int var;
void fun()
{
cout << "Member of Base2" << endl;
}
};
class Derived :public Base1, public Base2
{
public:
int var;
void fun()
{
cout << "Member of Derived " << endl;
}
};
int main()
{
Derived d;
Derived* p = &d;
d.var = 1;
d.fun();
(*p).Base1::var = 2;
(*p).Base1::fun();
p->Base2::var = 3;
p->Base2::fun();
return 0;
}
#include<iostream>
using namespace std;
class Base1
{
public:
int var;
void fun()
{
cout << "Member of Base1" << endl;
}
};
class Base2
{
public:
int var;
void fun()
{
cout << "Member of Base2" << endl;
}
};
class Derived :public Base1, public Base2
{
public:
int var;
void fun()
{
cout << "Member of Derived " << endl;
}
};
int main()
{
Derived d;
Derived* p = &d;
d.var = 1;
d.fun();
(*p).Base1::var = 2;
(*p).Base1::fun();
p->Base2::var = 3;
p->Base2::fun();
return 0;
}
#include<iostream>
using namespace std;
class Base0
{
public:
Base0(int var):var0(var){}
int var0;
void fun0()
{
cout << "Member of Base0" << endl;
}
};
class Base1 :virtual public Base0
{
public:
Base1(int var):Base0(var){}
int var1;
};
class Base2 :virtual public Base0
{
public:
Base2(int var) :Base0(var) {}
int var2;
};
class Derived :public Base1, public Base2
{
public:
Derived(int var):Base0(var),Base1(var1),Base2(var2){}
int var;
void fun()
{
cout << "Member of Derived" << endl;
}
};
int main()
{
Derived d(1);
d.var = 2;
d.fun();
return 0;
}
本文来自博客园,作者:赵千万,转载请注明原文链接:https://www.cnblogs.com/zhaoqianwan/p/17304226.html
千万千万赵千万