Re: a hard problem about template specification
<wangjk@ihep.ac.cn> a ?crit dans le message de news:
08235181-2c5c-46ff-a7c7-5b6312e00a54@j1g2000prb.googlegroups.com...
Hi, Eric and roadt, thanks your good suggestion!
I paste it again.
(1)
template<typename L, typename R, bool b1=false, bool b2=false>
struct A
{
A() {cout<<"1\n";}
};
(2)
template <typename L, typename R>
struct A<L, R, true, true>
{
A(){cout<<"2\n";}
int operator()(int i);
};
(3)
template< >
A<int,int>::operator()(int i)
{
cout<< i<<endl;
}
int main()
{
return (new A<int,int,true,true>)->operator()(5);
}
this print
2
5
I think the setence
(new A<int,int,true,true>)->operator()(5)
will call the operator()(int) of (2).
Thats is exactly what it does
But it call the operator()(int) of (3), it is so strange.
wait, (3) should be
template< > A<int,int,true,true>::operator()(int i) { ... }
not
template< > A<int,int>::operator()(int i) { ... }
the latter does not compile
-------------------
Eric Pruneau
Because there are 2 dafault bool parameters in template(1).
So I think the operator of (3) is equal to
template< > A<int,int, false, false>::operator()(int),
of course the (new A<int,int,true,true>)->operator()(5)
not match it.