Hello again. There's something wrong with the constructor in the above program. The compiler gives the following message w.r.t. to the third line from bottom "error: request for member `i' in `A', which is of non-class type".Code:#include <iostream> using namespace std; template <class T> class I1 { public: T i; I1(T a = 0): i(a){} ~I1(){} }; int main() { I1<int> A(); cout << A.i << endl; return 0; }
I can't see what the problem is. T is int, and both a and i are of type T, so surely i is an int. Any suggestions?
Also, a more general question. I have been learning C++ in my spare time for 4 or 5 months now, by working my way through the Stroustrup book. It went fine until I got to chapter 14 (templates). Now my brain seems to have gone on strike and nothing seems to make any sense any more. Is this normal??? (Fortunately, the next chapter, which deals with exceptions, is a piece of cake in comparison.)