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 

when to instantiate the declarations of a set of overload fu

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





PostPosted: Thu Feb 23, 2006 1:06 am    Post subject: when to instantiate the declarations of a set of overload fu Reply with quote



In the following program, the decaration of the third function(at point
3) triger errors on both g++ 3.3.1 and VC2005, but the first's (at
point 1) doesn't, i don't kown what the reason is, both functions'
template arguments deduced sucessfully and are not selected by overload
resolution, why only the third one's declaration triger errors?

template<typename T>
struct tc
{
template<typename _Tx>
struct bind
{
typedef int type;
int _Tx::* mp;
};

int T::* mp;
};

template<typename T0>
tc<T0> tf(T0,int) // 1)
{
return tc<T0>();
}
int tf(int,int) // 2)
{
return 1;
}
template<typename T0,typename T1>
typename tc<T0>::template bind<T1>::type tf(T0,T1) // 3)
{
return 0;
}
int main()
{
tf(0,0);
}

Are the declarations of all the templates deduced template arguments
successfully will be instantiated? or just the one be selected by
overload resolution? However, both cases can explain the above program.

Thanks.


[ 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: Fri Feb 24, 2006 3:06 pm    Post subject: Re: when to instantiate the declarations of a set of overloa Reply with quote



zf wrote:
Quote:
In the following program, the decaration of the third function(at point
3) triger errors on both g++ 3.3.1 and VC2005,[snip]

template<typename T> struct tc
{
template<typename _Tx> struct bind
{
typedef int type;
int _Tx::* mp;
};

int T::* mp;
};
[ the mentioned declarations.]

_Tx is a reserved name. If you don't know the exact rules, avoid prefix
_
and avoid double __ altogether. A single suffix _ is legal, e.g Tx_

HTH,
Michiel Salters


[ 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.