friend template function syntax
How does one declare a friend function of a template class? The code
below dates from 1999 but gcc 4.1.3 says e.g.
declaration of 'operator==' as non-function
expected ';' before '<' token
Not my style. I would declare these functions as members, and use
constant references. But it looks valid to me and presumably was, once
upon a time. Cf. http://pdos.csail.mit.edu/prolac/.
Many thanks.
--jkl
template <class C>
class IDCapsule {
C *_c;
public:
IDCapsule() : _c(0) { }
IDCapsule(const C *c) : _c((C *)c) { }
operator bool() const { return _c != 0; }
int hashcode() const { return (int)_c; }
C &operator*() const { return *_c; }
C *operator->() const { return _c; }
operator C *() const { return _c; }
C *obj() const { return _c; }
friend bool operator==<>(IDCapsule<C>, IDCapsule<C>);
friend bool operator==<>(IDCapsule<C>, IDCapsule<C>);
friend bool operator==<>(IDCapsule<C>, C*);
friend bool operator==<>(IDCapsule<C>, const C*);
friend bool operator!=<>(IDCapsule<C>, IDCapsule<C>);
friend bool operator!=<>(IDCapsule<C>, C*);
friend bool operator!=<>(IDCapsule<C>, const C*);
};
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]