ID非公開
ID非公開さん
2015/11/15 16:57
1回答
C++で同じ内容のクラスをまとめたい。 以下のプログラムのように、同じ内容を持つ構造体を一つにまとめる良い方法が知りたいです。
C++で同じ内容のクラスをまとめたい。 以下のプログラムのように、同じ内容を持つ構造体を一つにまとめる良い方法が知りたいです。 (SatouPlayer、SatouAlly、SatouEnemyやSuzuki~) //プログラム////////////////////////////////////////////// #include <stdio.h> struct Charcter { virtual void Move(){} virtual void Attack(){} }; //操縦者////////////////////////////////////////////////// struct Player : Charcter { void Move(){ printf("プレイヤー移動\n"); } }; struct Ally : Charcter { void Move(){ printf("味方移動\n"); } }; struct Enemy : Charcter { void Move(){ printf("エネミー移動\n"); } }; //佐藤////////////////////////////////////////////////// struct SatouPlayer : Player { void Attack(){ printf("佐藤アタック\n"); } }; struct SatouAlly : Ally { void Attack(){ printf("佐藤アタック\n"); } }; struct SatouEnemy : Enemy { void Attack(){ printf("佐藤アタック\n"); } }; //鈴木////////////////////////////////////////////////// struct SuzukiPlayer : Player { void Attack(){ printf("鈴木アタック\n"); } }; struct SuzukiAlly : Ally { void Attack(){ printf("鈴木アタック\n"); } }; struct SuzukiEnemy : Enemy { void Attack(){ printf("鈴木アタック\n"); } }; void main(){ Player* player = new SuzukiPlayer; player->Move(); player->Attack(); }
C言語関連・80閲覧・100
ベストアンサー
このベストアンサーは投票で選ばれました