This topic has been archived. It cannot be replied.
工作学习 / IT技术讨论 / What's the actual type passed as T to instanciate X? This puzzled me!
-blaise();
2002-2-19{145}(#373549@0)
template<typename T>
class X
{
};
template<template<typename U> class T1, typename T2>
class Y
{
};
Y<X, int> aY;
int main()
{
}
up一下
-blaise();
2002-2-21(#375306@0)
what C++ are you using? VC++?
-interview(intervieweree);
2002-2-21(#375637@0)
I think it should be -- Y<X<aT>, int> aY;
-clinux(C/Linux);
2002-2-21(#375664@0)
that's what I was thinking about,but doesn't work.
-blaise();
2002-2-21(#375750@0)
look at this you'll understand what X takes.
it actually can take anything.
-interview(intervieweree);
2002-2-21{211}(#375736@0)
template<class T>
class X
{
public:
T a;
};
template<template<typename U> class T1, class T2>
class Y
{
public:
T1<float> b;
};
X<int> x;
Y<X, int> aY;
int main()
{
return 0;
}
may i specify the float (... T1<float> ...) until I want to create aY?
-blaise();
2002-2-21{163}(#375749@0)
otherwise, if i fixed written T1<float>b, I can't have a T1<int> b, this lose the meaning for T1 to have a template parameter of U.
Did I express myself clearly?
you should do this.
-interview(intervieweree);
2002-2-21{126}(#375756@0)
....
template<template<typename U> class T1 , class T2>
class Y
{
public:
T1<T2> b;
};
Y<X, int> aY;
.....
COOL!
-blaise();
2002-2-21(#375761@0)
another way, actually same thing, but it's clearer
-interview(intervieweree);
2002-2-21{73}(#376192@0)
template<class T1, typename T2=X<T1> >
class Y
{
public:
T2 a;
};