#include <iostream>
#include <string>
struct Gun
{
virtual void reload() { std::cout << "Gun::reload\n" ; }
};
struct Pistol : public Gun
{
static const unsigned MagCap = 17 ;
std::string slidePos ;
unsigned roundsLeft ;
Pistol( ) : slidePos("closed"), roundsLeft(MagCap) {}
void reload()
{
std::cout << "Pistol::reload\n" ;
if ( slidePos == "open" )
roundsLeft = MagCap ;
else
{
slidePos = "open" ;
roundsLeft = MagCap+1 ;
}
slidePos = "closed" ;
}
};
int main()
{
Pistol p ;
Gun g ;
Gun* ptr = &p ;
ptr->reload() ;
ptr = &g ;
ptr->reload() ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKc3RydWN0IEd1bgp7CiAgICB2aXJ0dWFsIHZvaWQgcmVsb2FkKCkgeyBzdGQ6OmNvdXQgPDwgIkd1bjo6cmVsb2FkXG4iIDsgfQp9OwoKc3RydWN0IFBpc3RvbCA6IHB1YmxpYyBHdW4KewogICAgc3RhdGljIGNvbnN0IHVuc2lnbmVkIE1hZ0NhcCA9IDE3IDsKCiAgICBzdGQ6OnN0cmluZyBzbGlkZVBvcyA7CiAgICB1bnNpZ25lZCByb3VuZHNMZWZ0IDsKICAgIAogICAgUGlzdG9sKCApIDogc2xpZGVQb3MoImNsb3NlZCIpLCByb3VuZHNMZWZ0KE1hZ0NhcCkge30KCgogICAgdm9pZCByZWxvYWQoKQogICAgewogICAgICAgIHN0ZDo6Y291dCA8PCAiUGlzdG9sOjpyZWxvYWRcbiIgOwoKICAgICAgICBpZiAoIHNsaWRlUG9zID09ICJvcGVuIiApCiAgICAgICAgICAgIHJvdW5kc0xlZnQgPSBNYWdDYXAgOwogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHNsaWRlUG9zID0gIm9wZW4iIDsKICAgICAgICAgICAgcm91bmRzTGVmdCA9IE1hZ0NhcCsxIDsKICAgICAgICB9CiAgICAgICAgc2xpZGVQb3MgPSAiY2xvc2VkIiA7CiAgICB9Cn07CgppbnQgbWFpbigpCnsKICAgIFBpc3RvbCBwIDsKICAgIEd1biBnIDsKCiAgICBHdW4qIHB0ciA9ICZwIDsKICAgIHB0ci0+cmVsb2FkKCkgOwoKICAgIHB0ciA9ICZnIDsKICAgIHB0ci0+cmVsb2FkKCkgOwp9