Templated Functions .. ERROR: template id does not match template declaration

I wrote a function template and an explicitly specialized template function that simply takes 3 arguments and calculates the largest of them and prints.

A specialized function causes an error, while the template is working fine. But I want to work with char * type .

This is the error I get => error: template-id ‘Max<>’ for ‘void Max(char, char, char)’ does not match any template declaration

Below is my code:

    template <typename T>
    void Max(T& a,T& b,T& c)
    {
            if(a > b && a >> c)
            {
                    cout << "Max: " << a << endl;
            }
            else if(b > c && b > a)
            {
                    cout << "Max: " << b << endl;
            }
            else
            {
                    cout << "Max: " << c << endl;
            }
    }

    template <>
    void Max(char* a,char* b,char* c)
    {
            if(strcmp(a,b) > 0 )
            {
                    cout << "Max: " << a << endl;
            }
            else if(strcmp(b,c) > 0)
            {
                    cout << "Max: " << b << endl;
            }
            else
            {
                    cout << "Max: " << b << endl;
            }
}
+5
source share
2 answers

You need to take the pointers at the link:

template <> 
void Max(char*& a,char*& b,char*& c) 

, :

void Max(char* a, char* b, char* c)

. . Herb Sutter " ?"

+7

typedef:

typedef char * charPtr;
template <>
void Max(charPtr &a, charPtr &b, charPtr &c)
+3

All Articles