| www.delorie.com/archives/browse.cgi | search |
| From: | <l AT delorie DOT com> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | template friend |
| Date: | Sun, 28 May 2000 21:43:24 +0200 |
| Lines: | 57 |
| X-Priority: | 3 |
| X-MSMail-Priority: | Normal |
| X-Newsreader: | Microsoft Outlook Express 5.00.2919.6600 |
| X-Mimeole: | Produced By Microsoft MimeOLE V5.00.2919.6600 |
| Organization: | debitel.net - der Onlinedienst |
| X-NNTP-Posting-Host: | 62.54.41.57 |
| NNTP-Posting-Host: | mwnews.dnsg.net |
| Message-ID: | <393176dd@news.ivm.net> |
| X-Trace: | 28 May 2000 21:43:25 CET, mwnews.dnsg.net |
| X-Complaints-To: | usenet AT ivm DOT net |
| X-Admin-Comment: | X-NNTP-Posting... are valid if present |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
How do I declare a class template a friend of another class template?
I'm thinking of a situation like outlined below.
What's the correct syntax - in ANSI-C++
- for DJGPP 2.03 ?
/*---------------------------------------------------------------------*/
template<class T> class One
{
public:
One(T b) : a(b) {}
void SetValue(Two<T> &c)
{
c.x=a;
}
T a;
};
template<class TT> class Two
{
friend class One<TT>;
public:
Two(TT y) : x(y) {}
private:
TT x;
};
void main()
{
int i=3;
int j=4;
One<int> a(i);
Two<int> b(j);
a.SetValue(b);
}
/*---------------------------------------------------------------------*/
unbenannt.cpp:10: parse error before `>'
unbenannt.cpp: In method `void One<int>::SetValue(...)':
unbenannt.cpp:37: instantiated from here
unbenannt.cpp:12: `c' undeclared (first use this function)
unbenannt.cpp:12: (Each undeclared identifier is reported only once
unbenannt.cpp:12: for each function it appears in.)
/*---------------------------------------------------------------------*/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |