home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!ub4b!alcbel!ta7s49.alcbel.be
- From: ldup@ta7s49.alcbel.be (Luc Duponcheel)
- Newsgroups: comp.lang.c++
- Subject: templates and friends (again)
- Message-ID: <1949@alcbel.be>
- Date: 21 Jan 93 08:14:28 GMT
- Sender: ldup@alcbel.be
- Organization: Alcatel Bell Telephone, Antwerpen, Belgium
- Lines: 74
-
- Sorry, there were some little typing errors in my first mail (cut/paste ...).
- The (ugly) solutions were, as you might have guessed, template functions with
- a type template argument omly. So I repeat the mail .
-
-
- --------start--------------
-
-
- I have some question about templates and friends.
-
- Since friend templates are function templates, they cannot have non-type
- template arguments.
-
-
- Therefore the following example will not compile
-
- ---------begin------------
-
- #include <iostream.h>
-
- template<class T, int size>
- class Container {
- friend ostream &operator<<(ostream &, const Container<T,size> &) ;
- } ;
-
- template<classT, int size>
- ostream &operator<<(ostream &os, const Container<T,size> &c) {
- // do something
- return os ;
- }
-
- ----------end-------------
-
- The following example compiles
-
- ---------begin------------
-
- #include <iostream.h>
-
- template<class T, int size>
- class Container {
- friend ostream &operator<<(ostream &, const Container<T,5> &) ;
- friend ostream &operator<<(ostream &, const Container<T,10> &) ;
- // ...
- } ;
-
- template<classT>
- ostream &operator<<(ostream &os, const Container<T,5> &c) {
- // do something
- return os ;
- }
-
- template<classT>
- ostream &operator<<(ostream &os, const Container<T,10> &c) {
- // do something
- return os ;
- }
-
- // ...
-
- ----------end-------------
-
- I do NOT think this is the way to solve the problem.
-
- Are there any better solutions?
-
- P.S.
-
- What is the very reason for not allowing non-type template arguments
- for function templates?
-
-
-
-
-