F
flopbucket
Hi,
If I have:
template<class T>
class X
{
.....
};
then:
template<class U>
class Y
{
public:
typedef X<U> NormalType;
typedef X<const U> ConstType;
NormalType foo() { return NormalType(); }
};
How can I (or can I?) have conversion from NormalType to ConstType so
the following would work:
Y<int> bar;
ConstType i = bar.foo();
Can I have a constructor in Y like "Y(const Y<const T>&)" to provide
implicit conversion? If I do something in Y like:
template<class Z>
Y(const Z&)
That would apply to any type and try to convert, wouldnt it?
Is there a way I can specify I can accept a type "const T" when the
template is instantiated with just T?
Thanks for any tips.
If I have:
template<class T>
class X
{
.....
};
then:
template<class U>
class Y
{
public:
typedef X<U> NormalType;
typedef X<const U> ConstType;
NormalType foo() { return NormalType(); }
};
How can I (or can I?) have conversion from NormalType to ConstType so
the following would work:
Y<int> bar;
ConstType i = bar.foo();
Can I have a constructor in Y like "Y(const Y<const T>&)" to provide
implicit conversion? If I do something in Y like:
template<class Z>
Y(const Z&)
That would apply to any type and try to convert, wouldnt it?
Is there a way I can specify I can accept a type "const T" when the
template is instantiated with just T?
Thanks for any tips.