| View previous topic :: View next topic |
| Author |
Message |
υα Guest
|
Posted: Sun Apr 17, 2005 6:01 pm Post subject: Template Parameter Friends |
|
|
I know it's nonstandard,but is there any possibility to
declare a template parameter as a friend? It's an essential part
of the "property" library,which is quite useful
(unimportant for the answer).
I have g++ 3.4.2 and neither of the following compiles:
template <...>
class field_get
{
#1 friend T;
#2 friend class T;
#3 struct friend_maker
{
typedef T T2;
}
typedef friend_maker::T2 friend_type;
friend friend_type;
};
Please, is there something I can do about this?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Stefan Strasser Guest
|
Posted: Sun Apr 17, 2005 9:09 pm Post subject: Re: Template Parameter Friends |
|
|
υα schrieb:
| Quote: | I know it's nonstandard,but is there any possibility to
declare a template parameter as a friend? It's an essential part
of the "property" library,which is quite useful
(unimportant for the answer).
|
what property library?
| Quote: | Please, is there something I can do about this?
|
template<typename T>
struct befr{
typedef T type;
};
template<typename T>
struct A{
friend class befr<T>::type;
};
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Valentin Samko Guest
|
Posted: Mon Apr 18, 2005 9:04 am Post subject: Re: Template Parameter Friends |
|
|
υα wrote:
| Quote: | I know it's nonstandard,but is there any possibility to
declare a template parameter as a friend? It's an essential part
of the "property" library,which is quite useful
(unimportant for the answer).
I have g++ 3.4.2 and neither of the following compiles:
|
There is no universal solution, but there are a few compiler dependent
hacks, see the CUJ article
http://www.cuj.com/documents/s=8943/cujexp0312wilson2/
--
Valentin Samko
http://val.samko.info
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ralph Zhang Guest
|
Posted: Mon Apr 18, 2005 9:11 am Post subject: Re: Template Parameter Friends |
|
|
Why can't it compile? in VC7.1 it compiles very well:
template <typename T>
class field_get
{
friend class T;
};
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
υα Guest
|
Posted: Mon Apr 18, 2005 3:13 pm Post subject: Re: Template Parameter Friends |
|
|
Thanks! I knew about the article,but forgot to try the templated version.Now
it works.
P.S.:By "property library" I mean the concepts from Wilsons book from
"Imperfect C++",which is in one of his libraries.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|