Re: Totally omit default parameter brackets from template?
tony@donotspamme.ar wrote:
the latter can be written also as:
MyClass<> Instance3;
and here's finally the question: I'd like to use also this default form:
MyClass Instance3;
which of course will be perfectly equivalent to MyClass<> and MyClass<void>
How do I do it? I tried some namespace trick, but not successfully (which
doesn't mean it's not the right way to go, but just that I'm too lame to
successfully bring it to life).
Please note I am using VisualC++ 8.0 (a.k.a. 2005) targeting native x86
code on 32bit Windows and I do NOT care about portability for the specific
case, so any trick that would work with this compiler would be fine++ for
me.
You can't access both a non-template and a template class in the same
scope without namespace qualifying at least one of them. However, I
can't really see any benefit to giving a class template (which isn't a
type) and a particular specialization (which is a type) the same name -
just give the typedef for MyClass<> a different name.
You can do something ostensibly similar with functions of course:
template<class T>
void f()
{
}
void f()
{
f<void>();
}
f();
f<int>();
Tom