Code:
template <typename MyType>
void MyStrCopy(MyType &Str)
{
//Copy string here
}
In this example, I think you need to clarify what you want the template for ...
You can have template classes (like your list) and template functions (a little like a macro but with all the virtues of a 'real' function).
It seems that you are defining a template function to copy a string - what you should think about is a copy function that copies any object that can be traversed, like your list class (this also exists already but ignore that for now).
So your string class could provide a function 'begin' which gives access the first character, and a function 'end' which somehow indicates the last character has been reached, and your copy be performed on each character in between the two points.
Moving on to your list class, why not have that provide the same 'begin' and 'end' functions, then you can use your same copy function to copy lists. Maybe an array class would be a good idea and if you give that 'begin' and 'end' functions then ... etc.
'begin' and 'end' functionas are not the only option either - if your container class always go from 0 to length(), then you could use that functionality.
(Lots of these features are already covered by the standard library, often referred to as the standard template library, or STL, but you will see all that later - I am just trying to point you to some examples and I am sure you pick it up pretty quickly)
wrt instantiation, you basically think about what information is available to the compiler - you have to provide the rest:
Code:
template<typename S>
S copy(const S& s)
{
S new_s;
// i would be something called an 'iterator' here
// this code is not real, just to illustrate
for (i = s.start(); i!=s.end(); i++) new_s[i] = s[i];
return new_s;
}
template<typename To, typename From>
To change(const From& f)
{
return (To)f;
}
int main()
{
string s;
string another_s = copy(s);
/* here the compiler can tell that copy<string> will be invoked because it
the type of s is given */
rope r = change<rope>(s);
/* now we need to tell the compiler what version of change to instantiate.
the 'From' type is implicit but the 'To' type must be explicitly stated */
}
HTH