#include<iostream>
using namespace std;
class enemy{ //this is my base class
protected:
int attack;
public:
void attackpower(int a){
attack=a;
}
};
class ninja :public enemy{ // this is my first derived class
public:
void attack()
{cout<< " i am a ninja with " << attack << "power" << endl;}
};
class monster: public enemy{ ////this is my second derived class
void attack()
{
cout<<"i am a monster with "<< attack << "power"<<endl;
}
};
//main programs start
int main(){
ninja n;
monster m;
enemy *enemy1=&n;
enemy *enemy2=&m;
enemy1->attackpower(10);
enemy2->attackpower(90);
n.attack();
m.attack();
}
This is the error line
cout<<"i am a monster with "<< attack << "power"<<endl;
Aucun commentaire:
Enregistrer un commentaire