Topic: namespaces and templates : the using declaration in the standard
Author: "Aur lien Geron" <tessier.geron@wanadoo.fr>
Date: 1998/09/21 Raw View
Hi,
I would like to know what the standard says about the following
problems.
I have a template class which is defined in a namespace (like in the
STL) :
namespace test {
template <class T> cont { ... }
}
I'm surprised to see that the following code does not work (VC++ 5.0) :
void main() {
using test::cont; // ERROR : the template needs an argument !
}
First question : is this a standard behaviour (I read the draft but
couldn't find the information) ?
Moreover, the following code doesn't compile either :
void main() {
using test::cont<char>; // compiles, but doesn't seem to be
taken into
account
cont <char> myCont; // ERROR !!! The compiler says it has
never heard
about 'cont' !
}
Second question : is THIS a standard behaviour ? I doubt it!
Finally, the only solutions I found were :
1) test::cont<char> myCont; // (at least this works!)
2) using namespace test; // ok, but this is often impossible to use
because of name clashes
3) typedef test::cont<char> ContChar; // I don't like typedefs, but
maybe
it's the best solution in this case !
Can somebody help me out on this one, I would really appreciate ?
Thanks,
Aur lien Geron.
---
[ 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: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/09/21 Raw View
Aur=E9lien Geron<tessier.geron@wanadoo.fr> wrote:
>I have a template class which is defined in a namespace (like=20
>in the STL) :
>
>namespace test {
> template <class T> cont { ... }
>}
I assume you mean:
namespace test {
template <class T> struct cont { ... };
}
>I'm surprised to see that the following code does not work (VC++ 5.0) :
>void main() {
> using test::cont; // ERROR : the template needs an argument !
>}
This is good code. Given a correct definition of cont,=20
it is a compiler bug not to accept it.
>Moreover, the following code doesn't compile either :
>void main() {
> using test::cont<char>;=20
> cont <char> myCont;
>}
This is bad code, and the compiler should issue an error message.
That it doesn't is also a compiler bug.
--=20
Nathan Myers
ncm@nospam.cantrip.org http://www.cantrip.org/
[ 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 ]