c++ - How to get the integers 35 and 50 in the output of this program ? -


i new in c++ programming , been month started learning object oriented programming , learning program of inheritance , not getting output wanted. wrong in source code below.

  #include<iostream> using namespace std; class enemy{     private:         int attackpower;         public:             void enemys(int x)             {                 attackpower=x;             }      };              class monster : public enemy             {                 public:                  enemy::enemys;              };              class ninja : public enemy             {                 public:                  enemy::enemys;             };   int main() {     monster object1; cout<<"you points : - "<<endl;  object1.enemys( 35);      ninja object2; cout<<"you points  : - "<<endl; object2.enemys( 50);  } 

well output :

output : points : - points : -

i suppose integers mentioned after "you points : - 35 " , "you points - 50"

as per program not getting integers in output. wrong?

i new programming please kindly me.

thanks lot.

here's code makes (very slight) use of inheritance. maybe you'll find useful

  #include<iostream> using namespace std; class enemy{     private:         int attackpower;         public:             enemy(int ap)             {                 attackpower = ap;             }             int get_attackpower()             {                 return attackpower;             }      };          class monster : public enemy         {         public:             monster() : enemy(35)             {             }         };          class ninja : public enemy         {         public:             ninja() : enemy(50)             {             }         };   int main() {     monster object1;     cout<<"you points : - " << object1.get_attackpower() << endl;      ninja object2;     cout<<"you points  : - "<< object2.get_attackpower() << endl;  } 

output is

you points : - 35 points  : - 50 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -