#include <iostream>

#include <cstring>

using namespace std;


template <typename T>

T Max(T a,T b)

{

return a > b ? a : b;

}


template <>

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

{

cout<<"cahr* Max<char*>(char* a,char* b)"<<endl;

return strlen(a) > strlen(b) ? a : b;

}


template <>

const char* Max(const char* a,const char* b)

{

cout<<"const char* Max<const char*>(const char* a,const char* b)"<<endl;

return strcmp(a,b) > 0 ? a : b ;

}


int main()

{

cout<<Max(11,15)<<endl;

cout<<Max('T','Q')<<endl;

cout<<Max(3.5,7.9)<<endl;

cout<<Max("Simple","Best")<<endl;


char str1[]="Simple";

char str2[]="Best";

cout<<Max(str1,str2)<<endl;

return 0;

}


빨간색,보라색 부분인데 저게 원본 소스입니다

근데 내가 궁금한건 매개변수에 const 선언을 왜 해야하냐는거. 인자로 전달되는게 문자열 상수라서 그런건가?


근데 웃긴거 cosnt 를 지우면 빨간줄 뜬다 이말임. 근데 더 웃긴건 char *a ="Simple" 이렇게 저장가능하잖아


왜 도대체 빨간줄 띄우는건지 이해가 안가.


빨간줄에 마우스 가져다 대면 반환형으로는 오버로딩 을 구분?할수 없다던가 어쩌고 뜨는데 그거때문인가? 그거 구분하려고 const 선언을 한거야?