#include #include template class triad { protected: T a, b, c; public: triad(T s1, T s2, T s3); T operator[](int i); void print(); }; template ostream & operator<<(ostream & o, triad & t) { o << "triad(" << t[0] << "," << t[1] << "," << t[2] << ")"; return o; } void main() { triad x("ant", "bat", "cat"); triad y(11, 222, 3333); cout << x[1] << " " << y[0] << "\n"; cout << "x = " << x << "\n"; cout << "y = " << y << "\n"; } template triad::triad(T s1, T s2, T s3) { a = s1; b = s2; c = s3; } template T triad::operator[](int i) { if (i == 0) return a; else if (i == 1) return b; else if (i == 2) return c; else cerr << "Error!\n"; } template void triad::print() { cout << "triad(" << a << "," << b << "," << c << ")"; }