//純粋仮想関数を持っている抽象クラス class Zukei { public: virtual void Draw() = 0; //純粋仮想関数 }; |
/*★ 純粋仮想関数と抽象クラス 前田 稔 ★*/ #include <stdio.h> //純粋仮想関数を持っている抽象クラス class Zukei { public: virtual void Draw() = 0; //純粋仮想関数 }; class Maru : public Zukei { public: void Draw() { printf("○"); } }; int main() { Maru *p; p = new Maru; p->Draw(); return 0; } |
/*★ 純粋仮想関数と抽象クラス 前田 稔 ★*/ #include <stdio.h> //純粋仮想関数を持っている抽象クラス class Zukei { public: virtual void Draw() = 0; //純粋仮想関数 }; class Maru : public Zukei { public: void Draw() { printf("○"); } }; class Sankaku : public Zukei { public: void Draw() { printf("△"); } }; class Shikaku : public Zukei { public: void Draw() { printf("□"); } }; int main() { Zukei *p[10]; p[0] = new Maru; p[1] = new Sankaku; p[2] = new Sankaku; p[3] = new Shikaku; p[4] = new Shikaku; p[5] = new Shikaku; for(int i=0; i<6; i++) p[i]->Draw(); printf("\n\n"); for(int i=3; i<6; i++) p[i] = p[i+1]; for(int i=0; i<5; i++) p[i]->Draw(); return 0; } |
#include <iostream> class super { public: super(){}; ~super(){ std::cout << "super end" << std::endl; }; virtual void hoge() = 0; }; class child : public super { public: child(){}; ~child(){ std::cout << "child end" << std::endl; }; void hoge(){ std::cout << "hoge" << std::endl; }; }; void main() { super *test = new child(); test->hoge(); delete test; test = NULL; } |
virtual ~super() { std::cout << "super end" << std::endl; }; |