class Foo {
protected:
int a;
};
template<class T> class Setter : public T {
public:
void Set(int v) { T::a = v; }
};
template<class T> class Incrementer : public T {
public:
void Inc() { ++T::a; }
};
int main(int argc, char* argv[])
{
Setter< Foo > a;
Incrementer< Foo > b;
Setter< Incrementer< Foo > > c;
a.Set(5); // 1
a.Inc(); // 2
b.Set(5); // 3
b.Inc(); // 4
c.Set(5); // 5
c.Inc(); // 6
return 0;
}
Login in to like
Login in to comment