Citrix System Inc Interview Question
Software Engineer / DevelopersTeam: Shared file
Country: United States
Interview Type: Phone Interview
1. In C++ they are called templates and provide a compile-time evaluated method of parametric polymorphism. In practise you would define a class, class-member or method as a template, including the type parameters (using either the class or typename specifiers) and implement your logic based around the idea that you're type represents any compatible type which will be evaluated within the context of usage rather than where it is declared. This is how the STL is defined, providing a type-abstract set of algorithms, class and containers which provide common functionality to whatever built-in or user-defined types you require
2. C++ does not suffer from the boxing/unboxing problems in managed languages like C#. The only disadvantages of templates in C++ are that heavy use of them (e.g. boost or loki) can radically expand compilation times due the increased requirements of compile-time code generation. Also since they are evaluated at compile-time (not link-time), the compiler has to be aware of the full implementation of the template body in order to resolve it successfully, which means you can not separate the declaration from the implementation across separate header and source files (i.e. separate translation units), without exploiting mechanisms such as temple specialisation (which aren't appropriate in all cases).
1. Generic methods/classes accepts Generic parameters mostly denoted as parameter T, for example a generic method accepting two arguments and performing Addition operation. We can pass int, float, double etc.......data type to this generic method and it will perform the same operation and will return back the results. It means the methods operation is not dependent on a particular data type, hence called as a generic method.
- Anonymous January 15, 20142. The disadvantage of Generic method is that, it require Boxing (converting value type to object) and Unboxing (converting object type to value type), hence consume more resources and memory and impact the performance.