Skip to content

Instantly share code, notes, and snippets.

@W4RH4WK
Last active August 31, 2015 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save W4RH4WK/cdaff03df6e14bc9be46 to your computer and use it in GitHub Desktop.
Save W4RH4WK/cdaff03df6e14bc9be46 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class A {
protected:
int count;
public:
A(void) : count(0) {}
int getCount(void) {
return this->count;
}
void add(void) {
this->count++;
}
void add2(void) {
this->add();
this->add();
}
};
class B : public A {
public:
void add(void) {
this->count++;
this->count++;
}
};
int main(int argc, char *argv[])
{
A a;
a.add2();
cout << "a.count = " << a.getCount() << endl;
// a.count = 2
B b;
b.add2();
cout << "b.count = " << b.getCount() << endl;
// b.count = 2
return 0;
}
class A(object):
def __init__(self):
self.count = 0
def add(self):
self.count += 1
def add2(self):
self.add()
self.add()
class B(A):
def add(self):
self.count += 2
if __name__ == '__main__':
a = A()
a.add2()
print 'a.count =', a.count
# a.count = 2
b = B()
b.add2()
print 'b.count =', b.count
# b.count = 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment