Skip to content

Instantly share code, notes, and snippets.

@higaki
Created February 28, 2016 02:53
Show Gist options
  • Save higaki/1b954ea48a38441142e7 to your computer and use it in GitHub Desktop.
Save higaki/1b954ea48a38441142e7 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
class Super {
public:
Super(int v): value(v) {}
virtual int getValue() const {return value;}
protected:
int value;
};
class Sub: public Super {
public:
Sub(int v): Super(v), ratio(1.08) {}
virtual int getValue() const {return value * ratio;}
private:
double ratio;
};
using namespace std;
#define ARRSIZ(a) (sizeof(a)/sizeof((a)[0]))
#define ARRBGN(a) (a)
#define ARREND(a) ((a)+ARRSIZ(a))
int main()
{
vector<Super> values;
values.push_back(Super(100));
values.push_back(Sub(100));
for (vector<Super>::iterator i = values.begin(); i != values.end(); ++i)
cout << i->getValue() << endl;
cout << Sub(100).getValue() << endl;
Super v = Sub(100);
cout << v.getValue() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment