About template overloaded function .

I type the code on vc6.0 and vc2005,
but result're different between them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
using std::cout;
using std::endl;

template <typename T> T Max(T a, T b)
{
    if (a>=b)
    {
        return a;
    }

    return b;
}


char* Max(char* a, char* b)
{
    if (NULL==a || NULL==b)
    {
        if (NULL!=a)
        {
            return a;
        }
        if (NULL!=b)
        {
            return b;
        }
        return NULL;
    }

    int cmp_str =strcmp(a, b);

    if (cmp_str>=0)
    {
        return a;
    }

    return b;
}


int main(int argc, char* argv[])
{
    cout<<Max("a","b")<<endl;
    return 0;
}



on vc6.0 , can carry out function char* Max(char* a, char* b),
but on vc2005, template T Max(T a, T b) execute.

I change it, function const char* Max(cosnt char* a, const char* b),
vc2005, can carry out.

I want to konw why two VC++, have different about const char * and char * for template.

Thank you.
I ran both. VC2005 correctly uses const char* instead of char*.

GCC 4.x concures.
VC 6 is also known to be somewhat shakey when it comes to templates.
It is also quite old - throw away VC 6.
Topic archived. No new replies allowed.