typedef unsigned long ulong;
typedef MyClassWithAVeryLongName MCWAVLN;
How do you do this for a template class? I've tried the following with no
luck (MSVC++ 6.0 SP4):
typedef MyTemplateClass MTC; // doesn't work
typedef MyTemplateClass<T> MTC<T>; // doesn't work since it doesn't know
about T
typedef template< typename T >
MyTemplateClass<T>
template< typename T >
MTC<T>; // doesn't work
Can it even be done? Any ideas?
TIA
Alex
You can use 'typedef' to define an alias to a real type, not
to a templated one. With a template you can use 'typedef' to
define an alias to a template specialisation (but not to a
partial one).
You could try using #define to shorten the name.
#define MTC(T) MyTemplateClass<T>
Of course, you lose the angle brackets and are forced to use
parentheses.
Victor
--
Please remove capital A's from my address when replying by mail
Well, you can do this:
// Just to get a shorter name.
template< class T> class MTC : public MyTemplateClass<T> {};
or this
#define MTC MyTemplateClass
Dennis Yelle
--
I am a computer programmer and I am looking for a job.
There is a link to my resume here:
http://table.jps.net/~vert/
A typdef must alias a complete type, which a template is not.
The best you can do is typedef particular instantiations:
typedef MyTemplate<int> MTI;
The only way to (sort of) do what you're asking
is with a macro, as others have shown.
-Mike
Actually, this is not entirely correct. MTC will never be able to access
MyTemplateClass's private members this way! The remedy would be to make MTC
a friend of MyTemplateClass, so we're talking about "friend templates",
which the standard requires, but unfortunately, is not supported by all
compilers including mine (MSVC++ 6.0 SP4), as far as I know.
Alex
Looks like the last GOTW ...
I see another problem. If you use this to shorten names, and you
write a functions like:
template <class T>
void foo( const MTC<T>& m){
//....
}
you cannot use it with the long name anymore because you need a dynamic cast
for this. (Perhaps I understood something wrong ... still learning ....)
bye Ralf
"Gnarly New C++ Language Features (that you can finally use)"
http://www.cantrip.org/gnarly.html
Its not as pretty as the straight typedef that you describe.... its
mainly to do with member typedefs of template classes + the "typename"
keyword. The above link should explain it all.
Cheers
Will