Re: Replaces macros by metaprogramming
* Alf P. Steinbach:
C. Specialize the complete class: you can't specialize just a member
routine.
I'm sorry, I apologize, but the above statement seems to be in error.
I discovered, when trying to check the validity of that statement, that I have
real difficulties parsing and making sense of the standard's section on
templates, and that some of it, regarding what can and can't be specialized, is
internally self-contradictory (discussed in old thread in [comp.std.c++]).
Even the following is apparently OK:
<code>
#include <iostream>
void say( char const s[] ) { std::cout << s << std::endl; }
template <typename T>
struct Foo
{
virtual void a() { say( "general a" ); }
virtual void b() { say( "b" ); }
};
template<> void Foo<char>::a() { say( "specialized a" ); }
int main()
{
Foo<char> o;
o.a();
o.b();
}
</code>
I don't know where I got the idea from that one would have to specialize the class.
But anyway, I apologize for the disinformation.
Cheers,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!