ti***********@g mail.com wrote:
"At the implementation level, the primary difference is that C#
generic type substitutions are performed at runtime and generic type
information is thereby preserved for instantiated objects."
- http://msdn2.microsoft.com/en-us/library/c6cyy67b.aspx
Wonder if someone could elaborate this difference to me. I understand
performing substitutions at runtime is slow. But, it implies in c++
templates, the type information is not preserved for instantiated
objects. Is this true?
In C# the generics source code is actually compiled to generics
binary code that can be used by external code.
In C++ the template source can not be independent compiled
and is compiled into the binary code of using it.
The C++ way is not very elegant. If you have a template
class and you use it for 3 types in each of 10 source
files you actually end up with 30 copies of the code.
The C++ way is very practical, because in c# you have to
declare the generic type as inherit from this and that to be
able to use it for anything, while in C++ you do not
need to do anything, because the operations on the substituted
types are checked at compile time.
Arne