Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How Are Generics Different from Classic Visual C++ Templates?

0
Posted

How Are Generics Different from Classic Visual C++ Templates?

0

There are two main differences: in the programming model and in the underlying implementation. In the programming model, .NET generics can provide enhanced safety compared to classic Visual C++ templates. .NET generics have the notion of constraints, which gives you added type safety. On the other hand, .NET generics offer a more restrictive programming model—there are quite a few things that generics cannot do, such as using operators, because there is no way to constraint a type parameter to support an operator. This is not the case in classic Visual C++ templates where you can apply any operator you like on the type parameters. At compile time, the classic Visual C++ compiler will replace all the type parameters in the template with your specified type, and any incompatibility is usually discovered then. Both templates and generics can incur some code bloat, and both have mechanisms to limit that bloat. Instantiating a template with a specific set of types instantiates only the meth

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123