Topic: need of instantiation arguments in template declaration


Author: girod@dshp01.trs.ntc.nokia.com (Marc Girod)
Date: Tue, 15 Jun 1993 20:42:39 GMT
Raw View
Hi netters!

My compiler (HP C++ B2402/B2404 A.03.00) accepts two syntaxes
interchangeably, and I cannot find out whether it is right or wrong
doing so.

Here is my case:
------------------------------------------------------------
#include <iostream.h>

template <class T> class X {
  public:
 X() {}    // <T> illegal in X<T>()
 X* foo(X*);
 X<T>* bar(X<T>*);
 friend X<T>* boo(X<T>*); // <T> mandatory in X<T>*
};

// <T> needed here (both places), otherwise:
// error:  X needs template instantiation arguments (1772)
template <class T> X<T>* X<T>::foo(X<T>* x) {
 cout << "foo       x: " << x << endl;
 return this;
}

template <class T> X<T>* X<T>::bar(X<T>* x) {
 cout << "bar       x: " << x << endl;
 return this;
}

template <class T> X<T>* boo(X<T>* x) {
 cout << "boo       x: " <<  x << endl;
 return x;
}

main() {
 X<int> xi;
 cout << "        &xi: " << &xi << endl;
 X<int>* yi = xi.foo(&xi);
 cout << "xi.foo(&xi): " << yi << endl;
 X<int>* zi = xi.bar(&xi);
 cout << "xi.bar(&xi): " << zi << endl;
 X<int>* ti = far(&xi);
 cout << "   boo(&xi): " << ti << endl;
}
------------------------------------------------------------

The syntaxes for both the constructor and the friend function cases
are clearly documented in the ARM, although slightly contradictory.

But what about the other members than the constructor?

Regards!
--
+-----------------------------------------------------------------------------+
| Marc Girod - Nokia Telecommunications       Phone: +358-0-511 7703          |
| TL4E - P.O. Box 12                            Fax: +358-0-511 7432          |
| SF-02611 Espoo 61 - Finland              Internet: marc.girod@ntc.nokia.com |
|    X.400: C=FI, A=Elisa, P=Nokia Telecom, UNIT=TRS, SUR=Girod, GIV=Marc     |
+-----------------------------------------------------------------------------+