#include <iostream>
using namespace std;
class enemy{
public:
void setAttackPower(int a){
attackPower = a;
}
protected:
int attackPower;
};
class ninja : public enemy{
public:
void attack(){
cout << "ninja attack" << attackPower;
}
};
class monster: public enemy{
public:
void attack(){
cout << "I am a monster" << attackPower;
}
};
int main()
{
ninja n;
enemy *enemy1 = &n;
enemy1->setAttackPower(20); // working fine up to here,this is where I
// thought it would set the n objects attackPower to 20 but does not
n.attack();
}
ICAjaW5jbHVkZSA8aW9zdHJlYW0+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgZW5lbXl7CgogICBwdWJsaWM6CiAgICAgICB2b2lkIHNldEF0dGFja1Bvd2VyKGludCBhKXsKCiAgICAgICAgICAgYXR0YWNrUG93ZXIgPSBhOwogICAgICAgfQogICBwcm90ZWN0ZWQ6CiAgICBpbnQgYXR0YWNrUG93ZXI7Cgp9OwoKCmNsYXNzIG5pbmphIDogcHVibGljIGVuZW15ewoKICBwdWJsaWM6CgogICAgdm9pZCBhdHRhY2soKXsKCiAgICAgICAgY291dCA8PCAibmluamEgYXR0YWNrIiA8PCBhdHRhY2tQb3dlcjsKICAgIH0KCn07CgpjbGFzcyBtb25zdGVyOiBwdWJsaWMgZW5lbXl7CgogcHVibGljOgogICAgdm9pZCBhdHRhY2soKXsKCiAgICAgICAgY291dCA8PCAiSSBhbSBhIG1vbnN0ZXIiIDw8IGF0dGFja1Bvd2VyOwoKICAgIH0KfTsKCmludCBtYWluKCkKewogICBuaW5qYSBuOwogICBlbmVteSAqZW5lbXkxID0gJm47CiAgIGVuZW15MS0+c2V0QXR0YWNrUG93ZXIoMjApOyAvLyB3b3JraW5nIGZpbmUgdXAgdG8gaGVyZSx0aGlzIGlzIHdoZXJlIEkgCiAgLy8gIHRob3VnaHQgaXQgd291bGQgc2V0IHRoZSBuIG9iamVjdHMgYXR0YWNrUG93ZXIgdG8gMjAgYnV0IGRvZXMgbm90CiAgIG4uYXR0YWNrKCk7IAoKfQ==