Hello, forum-folks!
I'm new at this forum.
I use gnu C++ compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
template<class T>
void fun(T a)
{ std::cout << "fun(T) a: " << a << "\n"; }
template<class T>
void fun(T *a)
{ std::cout << "fun(T *) a: " << a << "\n"; }
template<>
void fun<>(char *a)
{ std::cout << "fun(char *) a: " << a << "\n"; }
int main()
{ fun(new char('X')); }
| |
This code works just fine. All is good and okey.
But, if i change the last template specialization
template<>
void fun<>(char *a)
to
template<>
void fun<char *>(char *a)
then the second template:
template<class T>
void fun(T *a)
will be called from main
and if I remove angle braces (and all between then)
from my last template all will be good again.
(will be called the third template)
My question is:
Why in this example fun(T *a) is called instead
fun<char *>(char *a).
I think that fun<char *>(char *a) is more suitable in this case.
???
Thank you all for your time! I will be waiting for your answers.
and sorry me please for my poor English.