Home | | Programming and Data Structure II | Generic Programming

Chapter: Programming and Data structures : C++ Programming Advanced Features

Generic Programming

Generic programming means that you are not writing source code that is compiled as-is but that yo collection of other objects.

GENERIC PROGRAMMING:

 

Generic programming means that you are not writing source code that is compiled as-is but that yo collection of other objects. But there's much more to generic programming. In the context of C++ .it means to write programs that are evaluated at compile time.

 

 

A basic example of generic programming are templates of containers: In a statically typed language like C++ you would have to declare separate containers that hold integers, floats, and other types or deal with pointers to void and therefore losing all type information.

 

 

Templates which are the C++ way of generic programming leverage this constraint by letting you define classes where one or more parameters are unspecified at the time you define the class. When you instance the template later you tell the compiler which type it should use to create the class out of the template.

 

 

Example: template<typename T> class MyContainer

 

{

 

// Container that deals with an arbitrary type T

};

 

void main()

 

{

 

// Make MyContainer take just ints. MyContainer<int> intContainer;

}

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Programming and Data structures : C++ Programming Advanced Features : Generic Programming |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.