C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Template Parameter Friends

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
υα
Guest





PostPosted: Sun Apr 17, 2005 6:01 pm    Post subject: Template Parameter Friends Reply with 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:

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





PostPosted: Sun Apr 17, 2005 9:09 pm    Post subject: Re: Template Parameter Friends Reply with quote



υα 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





PostPosted: Mon Apr 18, 2005 9:04 am    Post subject: Re: Template Parameter Friends Reply with quote



υα 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





PostPosted: Mon Apr 18, 2005 9:11 am    Post subject: Re: Template Parameter Friends Reply with quote

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





PostPosted: Mon Apr 18, 2005 3:13 pm    Post subject: Re: Template Parameter Friends Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.