I am having problems with template class specialization, see the code bellow, please.
template <typename T>
class Point
{
private
T x, y;
typedef T Type;
public:
Point ( const T & x_, const T & y_) : x ( x_ ), y ( y_ ) {}
};
template <typename Item>
struct TItems
{
typedef std::vector <Item> Type;
};
template <typename Item>
class C开发者_C百科ontainer
{
protected:
typename TItems <Item>::Type items;
public:
typedef Item type;
};
Is it possible to specialize Container class for Point ?
Updated question:
I tried the following code, is it valid?
template <typename T>
class Container < Point <T> >
{
};
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
Container <Point <double> > points;
}
You can, yes, but your syntax isn't quite right. As it stands, the compiler doesn't know what T
is, so you have to tell it that it is a template parameter:
template<typename T>
class Container<Point<T> > { };
yes you can specialize your class with that type Point <T>
.
Edit:
I tried the following code, is it valid?
If you've tried the following code ,don't you know whether it compiled or not ? 0_o
int _tmain(int argc, _TCHAR* argv[])
{
Container <Point <double> > points;
return 0; // return should be here nor program will exit before creating Container <Point <double> > points;
}
r
精彩评论