C++ Template class equivilent

  • Thread starter Thread starter Christoph
  • Start date Start date
C

Christoph

I'm curious if C# has the equivalent of a template class in C++.
Where, in C++, you can do something like the following:

CList<int> myList;
CList<byte> myList;
etc.

thnx,
Chris
 
Not in the current version - the next version will come with "generics"
which has a lot of the C++ template functionality.

Arild
 
Chris,

While the previous two posters are right about generics, it should be
noted that there will be a few limitations, and they are not exactly like
templates. The biggest advantage of Generics is that Generic type
definitions are created at run-time, not at compile time (unlike the C++ and
Java models) so that a List<T> is a List<T> everywhere and can be used
everywhere.

However, the major con is that you can not do something like this:

public class MyClass<T> : T
{
public void DoSomething()
{
this.CallAMethodOnT();
}
}

You can't do that kind of thing with Generics, like you could with C++
templates.

Hope this helps.
 
Back
Top