 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
template
<class TYPE1, class TYPE2> //function template
|
|
void
array_copy(TYPE1 dest[], TYPE2 source[], int size) {
|
|
for(int i=0; i < size; ++i)
|
|
dest[i] = source[i];
|
|
}
|
|
template<>
void array_copy(char* dest[], char* source[], int size) {
|
for(int i=0; i < size; ++i) {
|
|
dest[i] = new char[strlen(source[i]) +
1];
|
|
strcpy(dest[i], source[i]);
|
|
}
|
|
}
|
|
//This
specialized function is called when:
|
|
char
saying1[] = "Hello World";
|
|
char
saying2[] = "This is a great day!";
|
|
char*
s1[2] = {saying1, saying2};
|
|
char*
s2[2];
|
|
array_copy(s2,
s1, 2);
|
|