SlideShare a Scribd company logo
1 of 7
2011
Saket Kr. Pathak
Software Developer
3D Graphics




Fundamentals Of Programming C++
A quick review of fundamentals of C with an prospective view of implementation in daily day to
day life.
Fundamentals Of Programming C++

heiii ...:) what a visualization of template in real life haa haa :). Yes, it's true. Let's think
what we expect from a friend, who makes everything easy within the life, with just a cute
smiley face, who helps to make the life's situations easier to move forward within the
span.

mmmHHmmm, I think i am diverting to the way of philosophy from the way of C++.
Lets come Back :) and have a story we will discuss features of template along the way.

    Single parameter Template Function:
A gal was there ("was" because, it may possible, now the gal was not just gal, but become
wife, mom, mother-in-law etc.) who returns directly whatever she got, good or bad. As
here we have the template function as "gal" which returns the type of situation all she
got through parameters.

template <class situation>situation gal(situation good_time,
situation bad_time)
{
return (good_time < bad_time ? bad_time : good_time);
}

     Multiple parameter Template Function:
Next time i had seen a comparison among situations, here loving gal accepts whatever
she got and returns a smile in her face and type-cast the return value to good
situations/time. Here we have lovng_gal template function with multiple type
parameter.

template <class good_time, class bad_time>good_time
lvng_gal(good_time temp_1, bad_time temp_2)
{
return (temp_1 < temp_2 ? temp_2 : temp_1);
}

Now we have main function, as:

int main(int argc, _TCHAR* argv[])
{
     int inam_1, inam_2, iresult;
     long lnam_1, lnam_2, lresult;

       inam_1 = 3;
       inam_2 = inam_1++;

       iresult = gal<int>(inam_1, inam_2);
       printf("Greater Number(int): %dn", iresult);



Saket Kr. Pathak                                                                          Page 2
Fundamentals Of Programming C++

       lnam_1 = 1020304050;
       lnam_2 = lnam_1++;

       lresult = lvng_gal<long>(lnam_1, lnam_2);
       printf("Greater Number(long): %ldn", lresult);

       lresult = lvng_gal<int,long>(inam_1, lnam_2);
       printf("Greater Number(long): %ld", lresult);

       getchar();
       return 0;
}

    Single parameter Template Class:
After Some time the loving gal got some responsibilities and she comfortably deals
everyone she faces. As in form of template-class. Here gal the template class keeps the
members of different groups in a combined unit as family.

template <class member>       //iTempl - friends_group || ipair - gal
class gal
{
public:
     member family[2];
     gal(member nam_1, member nam_2);
     virtual ~gal();

       member getMax();
};

template <class member>
gal<member>::gal(member nam_1, member nam_2)
{
     family[0] = nam_1;
     family[1] = nam_2;
}

template <class member>
gal<member>::~gal()
{
}

template <class member>
member gal<member>::getMax()
{
     member result;



Saket Kr. Pathak                                                                   Page 3
Fundamentals Of Programming C++

       result = family[0]<family[1] ? family[1] : family[0];

       return result;
}

int main(int argc, _TCHAR* argv[])
{
     gal<double> work_time(120.0123, 102.3201);

       double result = work_time.getMax();

       printf("This is greater: %fn", result);

       getchar();
       return 0;
}

     Multiple parameter Template Class:
Here now the loving gal manages her life in both professional as well as family concern.
As per priority of family, who take care of her professionalism too, and shows the result
in command prompt ... through “printf(…)”:). This template class gal have different type
of parameter as professional_life class and family_life class. The implementation we
have as;

template <class professional_life, class family_life>
class gal
{
public:
     professional_life iCollect_1;
     family_life iCollect_2;
     gal(professional_life nam_1, family_life nam_2);
     virtual ~gal();

       family_life getMax_diff();
};

template <class professional_life, class family_life>
gal<professional_life, family_life>::gal(professional_life
nam_1, family_life nam_2)
{
     iCollect_1 = nam_1;
     iCollect_2 = nam_2;
}

template <class professional_life, class family_life>
gal<professional_life, family_life>::~gal()

Saket Kr. Pathak                                                                   Page 4
Fundamentals Of Programming C++

{}
template <class professional_life, class family_life>
family_life gal<professional_life, family_life>::getMax_diff()
{
     family_life result;

       result = iCollect_1<iCollect_2 ? iCollect_2 : iCollect_1;

       return result;
}

int main(int argc, _TCHAR* argv[])
{
     gal<int,long> laugh(120, 10203040);

       long result = laugh.getMax_diff();

       printf("This is greater: %ldn", result);

       getchar();
       return 0;
}


     Specialization within Template Classes:
Here the loving gal is showing all smartness with complete intellectual sense and all,
whatever the gifts she gets she knows its value and respects it in same manner. As the
template class gal has another specification for the parametric data type i.e. double
and she knows how to increment it. That’s the smart sense of humor in my loving gal
template class  and implemented as;

template <class good_time>                      //iTempl - good_time
class gal
{
public:
     good_time elem;
     gal(good_time iVal);
     virtual ~gal();
     good_time increase();
};

template <class good_time>
gal<good_time>::gal(good_time iVal)
{
     elem = iVal;
}


Saket Kr. Pathak                                                                   Page 5
Fundamentals Of Programming C++

template <class good_time>
gal<good_time>::~gal()
{
}

template <class good_time>
good_time gal<good_time>::increase()
{
     return ++elem;

}

template <>
class gal<double>
{
public:
     double elem;
     gal(double iVal);
     virtual ~gal();
     double increase();
};

gal<double>::gal(double iVal)
{
     elem = iVal;
}

gal<double>::~gal()
{
}

double gal<double>::increase()
{
     elem = elem + 0.000001f;
     return elem;
}

int main(int argc, _TCHAR* argv[])
{
     gal<int> fun(3);
     printf("Int value: %dn", fun.increase());

       gal<double> smiles(0.000000f);
       printf("Double value: %fn", smiles.increase());

       getchar();
       return 0;

Saket Kr. Pathak                                          Page 6
Fundamentals Of Programming C++

}

Hii all, here I had done it and found a bit emotional essence regarding gals within C++
syntax :). Whatever it's a mistake :), and I don’t know how I slipped into this but if you
will try to feel it, I can bet you never forget concepts of Template in your life. Although
any one reads it or not is hardly matters for me, because I do this for my pleasure, I try
to view the concept within society, culture and philosophy. After all "Kurt
Koffka" says: Philosophy is the mother of all sciences.

Take care ... in someone's style ... not mine ... I used to say ... ctch u again ... :)


References:
http://www.cplusplus.com/doc/tutorial/templates/
http://www.iis.sinica.edu.tw/~kathy/vcstl/templates.htm
http://personal.stevens.edu/~wwang3/C++%20Templates%20Tutorial.pdf




Saket Kr. Pathak                                                                          Page 7

More Related Content

What's hot

Array within a class
Array within a classArray within a class
Array within a classAAKASH KUMAR
 
C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...
C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...
C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...Rishikesh Agrawani
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheoryKnoldus Inc.
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With ScalaKnoldus Inc.
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
C++ Returning Objects
C++ Returning ObjectsC++ Returning Objects
C++ Returning ObjectsJay Patel
 
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++Jay Patel
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2rohassanie
 
constructors and destructors in c++
constructors and destructors in c++constructors and destructors in c++
constructors and destructors in c++HalaiHansaika
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayimtiazalijoono
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
 

What's hot (20)

Templates2
Templates2Templates2
Templates2
 
Array within a class
Array within a classArray within a class
Array within a class
 
C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...
C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...
C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
C++ Templates 2
C++ Templates 2C++ Templates 2
C++ Templates 2
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With Scala
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Arrays
ArraysArrays
Arrays
 
C++ Returning Objects
C++ Returning ObjectsC++ Returning Objects
C++ Returning Objects
 
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
C arrays
C arraysC arrays
C arrays
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
constructors and destructors in c++
constructors and destructors in c++constructors and destructors in c++
constructors and destructors in c++
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 

Viewers also liked

Exception handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaException handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaManoj_vasava
 
file handling c++
file handling c++file handling c++
file handling c++Guddu Spy
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handlingsanya6900
 
Exception Handling in C++
Exception Handling in C++Exception Handling in C++
Exception Handling in C++Deepak Tathe
 
Template at c++
Template at c++Template at c++
Template at c++Lusain Kim
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template LibraryIlio Catallo
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++Tech_MX
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++Laxman Puri
 
This pointer .17
This pointer .17This pointer .17
This pointer .17myrajendra
 
Stl (standard template library)
Stl (standard template library)Stl (standard template library)
Stl (standard template library)Hemant Jain
 
[KOSSA] C++ Programming - 14th Study - template
[KOSSA] C++ Programming - 14th Study - template[KOSSA] C++ Programming - 14th Study - template
[KOSSA] C++ Programming - 14th Study - templateSeok-joon Yun
 
How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)Sangharsh agarwal
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15Kumar
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++ppd1961
 
Exception Handling
Exception HandlingException Handling
Exception HandlingAlpesh Oza
 
New operator and methods.15
New operator and methods.15New operator and methods.15
New operator and methods.15myrajendra
 

Viewers also liked (20)

Exception handling
Exception handlingException handling
Exception handling
 
Exception handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaException handling in c++ by manoj vasava
Exception handling in c++ by manoj vasava
 
file handling c++
file handling c++file handling c++
file handling c++
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 
Exception Handling in C++
Exception Handling in C++Exception Handling in C++
Exception Handling in C++
 
Template at c++
Template at c++Template at c++
Template at c++
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
This pointer .17
This pointer .17This pointer .17
This pointer .17
 
Stl (standard template library)
Stl (standard template library)Stl (standard template library)
Stl (standard template library)
 
[KOSSA] C++ Programming - 14th Study - template
[KOSSA] C++ Programming - 14th Study - template[KOSSA] C++ Programming - 14th Study - template
[KOSSA] C++ Programming - 14th Study - template
 
How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
New operator and methods.15
New operator and methods.15New operator and methods.15
New operator and methods.15
 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
 

Similar to C++ Template

20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstractionIntro C# Book
 
Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonPython Ireland
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdfrd1742
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010singingfish
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02CIMAP
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handlingSuite Solutions
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosIgor Sobreira
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Django Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryDjango Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryPamela Fox
 

Similar to C++ Template (20)

Classes and Inheritance
Classes and InheritanceClasses and Inheritance
Classes and Inheritance
 
Oop lecture1
Oop lecture1Oop lecture1
Oop lecture1
 
chapt02 (1).ppt
chapt02 (1).pptchapt02 (1).ppt
chapt02 (1).ppt
 
chapt02.ppt
chapt02.pptchapt02.ppt
chapt02.ppt
 
C++chapt002a.ppt
C++chapt002a.pptC++chapt002a.ppt
C++chapt002a.ppt
 
cht02.ppt
cht02.pptcht02.ppt
cht02.ppt
 
chapt02.ppt
chapt02.pptchapt02.ppt
chapt02.ppt
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in Python
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdf
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazos
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Django Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryDjango Admin: Widgetry & Witchery
Django Admin: Widgetry & Witchery
 

More from Saket Pathak

Wan Important Questions
Wan Important QuestionsWan Important Questions
Wan Important QuestionsSaket Pathak
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignmentSaket Pathak
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Saket Pathak
 
A Guy and gal in STL
A Guy and gal in STLA Guy and gal in STL
A Guy and gal in STLSaket Pathak
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in CSaket Pathak
 
GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?Saket Pathak
 
Malloc, calloc, realloc
Malloc, calloc, reallocMalloc, calloc, realloc
Malloc, calloc, reallocSaket Pathak
 
C++ diamond problem
C++ diamond problemC++ diamond problem
C++ diamond problemSaket Pathak
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++Saket Pathak
 

More from Saket Pathak (14)

Wan Important Questions
Wan Important QuestionsWan Important Questions
Wan Important Questions
 
Wan notes
Wan notesWan notes
Wan notes
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignment
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
A Guy and gal in STL
A Guy and gal in STLA Guy and gal in STL
A Guy and gal in STL
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?
 
C++ friendship
C++ friendshipC++ friendship
C++ friendship
 
Copy constructor
Copy constructorCopy constructor
Copy constructor
 
Malloc, calloc, realloc
Malloc, calloc, reallocMalloc, calloc, realloc
Malloc, calloc, realloc
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
C++ diamond problem
C++ diamond problemC++ diamond problem
C++ diamond problem
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

C++ Template

  • 1. 2011 Saket Kr. Pathak Software Developer 3D Graphics Fundamentals Of Programming C++ A quick review of fundamentals of C with an prospective view of implementation in daily day to day life.
  • 2. Fundamentals Of Programming C++ heiii ...:) what a visualization of template in real life haa haa :). Yes, it's true. Let's think what we expect from a friend, who makes everything easy within the life, with just a cute smiley face, who helps to make the life's situations easier to move forward within the span. mmmHHmmm, I think i am diverting to the way of philosophy from the way of C++. Lets come Back :) and have a story we will discuss features of template along the way.  Single parameter Template Function: A gal was there ("was" because, it may possible, now the gal was not just gal, but become wife, mom, mother-in-law etc.) who returns directly whatever she got, good or bad. As here we have the template function as "gal" which returns the type of situation all she got through parameters. template <class situation>situation gal(situation good_time, situation bad_time) { return (good_time < bad_time ? bad_time : good_time); }  Multiple parameter Template Function: Next time i had seen a comparison among situations, here loving gal accepts whatever she got and returns a smile in her face and type-cast the return value to good situations/time. Here we have lovng_gal template function with multiple type parameter. template <class good_time, class bad_time>good_time lvng_gal(good_time temp_1, bad_time temp_2) { return (temp_1 < temp_2 ? temp_2 : temp_1); } Now we have main function, as: int main(int argc, _TCHAR* argv[]) { int inam_1, inam_2, iresult; long lnam_1, lnam_2, lresult; inam_1 = 3; inam_2 = inam_1++; iresult = gal<int>(inam_1, inam_2); printf("Greater Number(int): %dn", iresult); Saket Kr. Pathak Page 2
  • 3. Fundamentals Of Programming C++ lnam_1 = 1020304050; lnam_2 = lnam_1++; lresult = lvng_gal<long>(lnam_1, lnam_2); printf("Greater Number(long): %ldn", lresult); lresult = lvng_gal<int,long>(inam_1, lnam_2); printf("Greater Number(long): %ld", lresult); getchar(); return 0; }  Single parameter Template Class: After Some time the loving gal got some responsibilities and she comfortably deals everyone she faces. As in form of template-class. Here gal the template class keeps the members of different groups in a combined unit as family. template <class member> //iTempl - friends_group || ipair - gal class gal { public: member family[2]; gal(member nam_1, member nam_2); virtual ~gal(); member getMax(); }; template <class member> gal<member>::gal(member nam_1, member nam_2) { family[0] = nam_1; family[1] = nam_2; } template <class member> gal<member>::~gal() { } template <class member> member gal<member>::getMax() { member result; Saket Kr. Pathak Page 3
  • 4. Fundamentals Of Programming C++ result = family[0]<family[1] ? family[1] : family[0]; return result; } int main(int argc, _TCHAR* argv[]) { gal<double> work_time(120.0123, 102.3201); double result = work_time.getMax(); printf("This is greater: %fn", result); getchar(); return 0; }  Multiple parameter Template Class: Here now the loving gal manages her life in both professional as well as family concern. As per priority of family, who take care of her professionalism too, and shows the result in command prompt ... through “printf(…)”:). This template class gal have different type of parameter as professional_life class and family_life class. The implementation we have as; template <class professional_life, class family_life> class gal { public: professional_life iCollect_1; family_life iCollect_2; gal(professional_life nam_1, family_life nam_2); virtual ~gal(); family_life getMax_diff(); }; template <class professional_life, class family_life> gal<professional_life, family_life>::gal(professional_life nam_1, family_life nam_2) { iCollect_1 = nam_1; iCollect_2 = nam_2; } template <class professional_life, class family_life> gal<professional_life, family_life>::~gal() Saket Kr. Pathak Page 4
  • 5. Fundamentals Of Programming C++ {} template <class professional_life, class family_life> family_life gal<professional_life, family_life>::getMax_diff() { family_life result; result = iCollect_1<iCollect_2 ? iCollect_2 : iCollect_1; return result; } int main(int argc, _TCHAR* argv[]) { gal<int,long> laugh(120, 10203040); long result = laugh.getMax_diff(); printf("This is greater: %ldn", result); getchar(); return 0; }  Specialization within Template Classes: Here the loving gal is showing all smartness with complete intellectual sense and all, whatever the gifts she gets she knows its value and respects it in same manner. As the template class gal has another specification for the parametric data type i.e. double and she knows how to increment it. That’s the smart sense of humor in my loving gal template class  and implemented as; template <class good_time> //iTempl - good_time class gal { public: good_time elem; gal(good_time iVal); virtual ~gal(); good_time increase(); }; template <class good_time> gal<good_time>::gal(good_time iVal) { elem = iVal; } Saket Kr. Pathak Page 5
  • 6. Fundamentals Of Programming C++ template <class good_time> gal<good_time>::~gal() { } template <class good_time> good_time gal<good_time>::increase() { return ++elem; } template <> class gal<double> { public: double elem; gal(double iVal); virtual ~gal(); double increase(); }; gal<double>::gal(double iVal) { elem = iVal; } gal<double>::~gal() { } double gal<double>::increase() { elem = elem + 0.000001f; return elem; } int main(int argc, _TCHAR* argv[]) { gal<int> fun(3); printf("Int value: %dn", fun.increase()); gal<double> smiles(0.000000f); printf("Double value: %fn", smiles.increase()); getchar(); return 0; Saket Kr. Pathak Page 6
  • 7. Fundamentals Of Programming C++ } Hii all, here I had done it and found a bit emotional essence regarding gals within C++ syntax :). Whatever it's a mistake :), and I don’t know how I slipped into this but if you will try to feel it, I can bet you never forget concepts of Template in your life. Although any one reads it or not is hardly matters for me, because I do this for my pleasure, I try to view the concept within society, culture and philosophy. After all "Kurt Koffka" says: Philosophy is the mother of all sciences. Take care ... in someone's style ... not mine ... I used to say ... ctch u again ... :) References: http://www.cplusplus.com/doc/tutorial/templates/ http://www.iis.sinica.edu.tw/~kathy/vcstl/templates.htm http://personal.stevens.edu/~wwang3/C++%20Templates%20Tutorial.pdf Saket Kr. Pathak Page 7