Tao Wang wrote:[color=blue]
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
PengYu.UT@gmail.com wrote:[color=green]
> > For example, I want the return_type of the two arguments of Expr2 be
> > the same. Otherwise, the compilor should give an error.
> >
> > Would you please tell me how to do that?
> >
> > Thanks,
> > Peng
> >
> >
> > template <typename T>
> > struct Expr1{
> > typedef T return_type;
> > };
> >
> > template <typename E, typename T>
> > struct Expr2;
> >
> > template <typename E1, typename E2>
> > struct Expr2 {//I want E1 and E2's return_type be the same.
> > typedef typename E1::return_type return_type;
> > };
> >
> > int main(int argc, char *argv[]){
> > Expr2<Expr1<int>, Expr1<double> > a;
> > }
> >[/color]
>
> To avoid the problem, why don't use one type, if two type are actually same?
>
> template <typename T>
> struct Expr1{
> typedef T return_type;
> };
>
> template <typename E>
> struct Expr2 {
> typedef typename E::return_type return_type;
> };
>
> int main(int argc, char *argv[]){
> Expr2<Expr1<int> > a;
> return 0;
> }[/color]
Because I might have Expr3 which can be used as the template arguments
of Expr2.
template <typename T>
struct Expr3{
typedef std::complex<T> return_type;
};