fork(1) download
  1. #include <typeinfo>
  2. #include "warrior.h"
  3. #include "magician.h"
  4. #ifndef MAN_H
  5. #define MAN_H
  6.  
  7. class man
  8. {
  9. public:
  10. man();
  11. virtual ~man();
  12. int get_hp();
  13. int get_mp();
  14. int get_level();
  15. template <class T> void upgrade(T *t,int n);
  16.  
  17. protected:
  18. int hp;
  19. int mp;
  20. int level;
  21. };
  22.  
  23. template <class T>
  24. void man::upgrade(T *t,int n){
  25. t->level = t->level +1;
  26.  
  27. //原本的解法
  28. /*
  29. if(n==1){
  30.   t->hp = t->hp*2;
  31.   t->mp = t->mp*3;
  32.   }
  33.   else if(n==2){
  34.   t->hp = t->hp*3;
  35.   t->mp = t->mp*2;
  36.   }*/
  37.  
  38. //想改成類似下面這種
  39. if(typeid(t) == typeid(magician)){
  40. t->hp = t->hp*2;
  41. t->mp = t->mp*3;
  42. }
  43. else if(typeid(t) == typeid(warrior)){
  44. t->hp = t->hp*3;
  45. t->mp = t->mp*2;
  46. }
  47. }
  48. #endif // MAN_H
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:21: fatal error: warrior.h: No such file or directory
 #include "warrior.h"
                     ^
compilation terminated.
stdout
Standard output is empty