Topic: template class visible from two namespaces
Author: James Kuyper <kuyper@wizard.net>
Date: 2000/08/04 Raw View
Hicham BOUHMADI wrote:
>
> Hi.
> I have two question. I want a class to be visible from 2 namespaces.
> in the case of a non-template class. I find the solution that consist on
> declaring it in one namespace and typedef-ing it in the second. This works
> fine... :-)
> The problem is that my real class is a template class.
> So is there any way to typedef a template class based on a template class. I
> want to write something like this:
> namespace A {
> template <typename X> class toto {};
> }
> namespace B {
> template <typename X> typedef A::toto<X> toto<X>
> }
>
> If there is no way to make such typedefs, so how can I make my super class
> toto be reachable from A and from B?
The closest there is to a templated typedef in C++ would be the
following:
template <typename X> class Name1
{
typedef A::toto<X> Name2;
}
Then B::Name1<T>::Name2 means A::toto<T>. Note: I usually have trouble
choosing Name1 and Name2 in this instance.
However, for your purposes you don't want a typedef, you want a 'using
declaration'. Just put
using A::toto;
into your namespace B block. Then B::toto<T> becomes an alternate way of
saying A::toto<T>.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Stefan Sommer <sommer@tecmath.de>
Date: 2000/08/04 Raw View
namespace A {
template <typename X> class toto {};
}
namespace B {
using A::toto;
}
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Hicham BOUHMADI" <hicham@citeweb.net>
Date: 2000/08/03 Raw View
Hi.
I have two question. I want a class to be visible from 2 namespaces.
in the case of a non-template class. I find the solution that consist on
declaring it in one namespace and typedef-ing it in the second. This works
fine... :-)
The problem is that my real class is a template class.
So is there any way to typedef a template class based on a template class. I
want to write something like this:
namespace A {
template <typename X> class toto {};
}
namespace B {
template <typename X> typedef A::toto<X> toto<X>
}
If there is no way to make such typedefs, so how can I make my super class
toto be reachable from A and from B?
Thanks lot!
Hicham BOUHMADI hicham@citeweb.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]