摘要:
基类与派生类之间的互相转换,使用指针的情况 源程序: #include<iostream> using namespace std; class CBase { protected: int n; public: CBase(int i):n(i){} void Print() { cout<<"C 阅读全文
posted @ 2020-01-12 19:16
bobo哥
阅读(246)
评论(0)
推荐(0)
摘要:
派生类中的复制构造函数 源程序: #include<iostream> using namespace std; class A { public: A() //默认构造函数 { i=100; cout<<"类A默认构造函数"<<endl; } A(const A&s) //复制构造函数 { i=s 阅读全文
posted @ 2020-01-12 19:03
bobo哥
阅读(173)
评论(0)
推荐(0)
摘要:
互包含的类 源程序: #include<iostream> #include<string> using namespace std; class B; class A { public: int aInt; B *bPoint=NULL; void SetValue(int v) { aInt=v 阅读全文
posted @ 2020-01-12 18:58
bobo哥
阅读(138)
评论(0)
推荐(0)
摘要:
虚基类 源程序: #include <iostream> using namespace std; class A{ public: int a; void showa(){ cout<<"a="<<a<<endl; } }; class B:virtual public A{ public: in 阅读全文
posted @ 2020-01-12 18:23
bobo哥
阅读(131)
评论(0)
推荐(0)
摘要:
抽象类示例 源程序: #include <iostream> using namespace std; class A{ private: int a; public: virtual void print()=0; void func1(){ cout<<"func1"<<endl; } }; c 阅读全文
posted @ 2020-01-12 18:19
bobo哥
阅读(176)
评论(0)
推荐(0)
摘要:
不使用虚析构函数的情况 源程序: #include <iostream> using namespace std; class ABase{ public: ABase(){ cout<<"ABase构造函数"<<endl; } ~ABase(){ cout<<"ABase::析构函数"<<endl 阅读全文
posted @ 2020-01-12 18:10
bobo哥
阅读(207)
评论(0)
推荐(0)
摘要:
多态与非多态的比较 源程序: #include <iostream> using namespace std; class A{ public: void func1(){ cout<<"A::func1"<<endl; } virtual void func2(){ cout<<"A::func2 阅读全文
posted @ 2020-01-12 18:06
bobo哥
阅读(204)
评论(0)
推荐(0)
摘要:
在构造函数和析构函数中调用虚函数 源程序: #include <iostream> using namespace std; class A{ public: virtual void hello(){ cout<<"A::hello"<<endl; } virtual void bye(){ co 阅读全文
posted @ 2020-01-12 18:01
bobo哥
阅读(126)
评论(0)
推荐(0)
摘要:
在成员函数中调用虚函数 源程序: #include <iostream> using namespace std; class CBase{ public: void func1(){ cout<<"CBase::func1()"<<endl; func2(); func3(); } virtual 阅读全文
posted @ 2020-01-12 17:53
bobo哥
阅读(407)
评论(0)
推荐(0)
摘要:
使用多态处理图形示例 源程序: #include <iostream> #include <cmath> using namespace std; class CShape { protected: double acreage; public: CShape() { //cout<<"基类构造函数 阅读全文
posted @ 2020-01-12 17:36
bobo哥
阅读(174)
评论(0)
推荐(0)
摘要:
多态机制下对象存储空间的大小 源程序: #include <iostream> using namespace std; class A { public: int i; virtual void func(); virtual void func2(); }; class B :public A 阅读全文
posted @ 2020-01-12 09:24
bobo哥
阅读(119)
评论(0)
推荐(0)
摘要:
基类引用实现多态 源程序: #include <iostream> using namespace std; class A { public: virtual void Print() { cout << "A::Print" << endl; } }; class B :public A { p 阅读全文
posted @ 2020-01-12 09:15
bobo哥
阅读(195)
评论(0)
推荐(0)
摘要:
用基类指针访问基类对象及派生类对象 源程序: #include <iostream> #include <string> using namespace std; class A { public: void put_name(string s) { name = s; } virtual void 阅读全文
posted @ 2020-01-12 09:10
bobo哥
阅读(140)
评论(0)
推荐(0)

浙公网安备 33010602011771号