Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Demystifying Templates in C++
Rating: 4.2 out of 5(37 ratings)
269 students

Demystifying Templates in C++

Illuminating neglected, misunderstood, and misused shades of Templates in C++
Last updated 6/2018
English

What you'll learn

  • You will gain a deeper understanding of the exact behaviors of templates in C++
  • Students will gain a solid understadning of templates and how to use them
  • Students will understand How to avoid the pitfalls associated with templates
  • Students would be introduced to Standard Template Library (STL)
  • You would understand How to reuse source code without threatening performance or safety
  • You would learn How to increase the efficiency of C++ programs

Course content

3 sections21 lectures2h 8m total length
  • Introduction7:33

    A template is a cookie-cutter that specifies how to cut cookies that all look pretty much the same (although the cookies can be made of various kinds of dough, they’ll all have the same basic shape). In the same way, a class template is a cookie cutter for a description of how to build a family of classes that all look basically the same, and a function template describes how to build a family of similar looking functions.

    This is an introduction to templates in C. Basically there are 2 types of templates:

    • Function template
    • Class templates

    In this section function templates would be discussed.

  • Syntax and Grammar6:16

    "Inheritance and composition provide a way to reuse object code. The template feature in C++ provides a way to reuse source code"

    In this video, you would learn syntax of function template along with an alternative to the program written in the previous topic with the function overloading. 

    Here is important note:
    In the video you may notice a minor difference between narration and code. Since max is a predefined template in the library, the name of the function template and template functions have been replaced by maxarg. 

  • Overloading a function template8:37
  • Internal working of function template6:33

    The video explains mysterious operations taken place under the hood.

    It shows also how instantiation is performed by the compiler.  

  • Template taking parameterized and non-parameterized type arguments4:21

    Function template can take parameterized type as well as non-parametarized type as arguments. Here is a video to explain the same.

  • Argument deduction in function template2:47

    When you call a function template, the compiler tries to deduce the template type. Most of the time it can do that successfully, but every once in a while you may want to help the compiler deduce the right type — either because it cannot deduce the type at all, or perhaps because it would deduce the wrong type.

    For example, you might be calling a function template that doesn’t have any parameters of its template argument types, or you might want to force the compiler to do certain promotions on the arguments before selecting the correct function template. In these cases you’ll need to explicitly tell the compiler which instantiation of the function template should be called.

    The same is explained here in the video

  • Argument Matching7:46

    All programs in this lecture are compiled using old C compiler. The intention is to exhibit the journey of templates from to old versions to current versions. 

    If you are not interested in the history, you can straightaway skip this lecture and move to next lecture. The learning process won't be hampered. 

    If you want to peep inside the history, just sit and enjoy listening and viewing programs. 

  • 3-Steps Argument Matching Rules4:19

    Interesting set of rule based on earlier matching rules covered in function overloading section in this course earlier

  • Multiple Parameterized Template8:50

    You will learn the method to write multiple templates as a parameter

  • Function template with class instance7:48

    In this concluding lecture of section 1, you would learn how to create an instance of a template taking instance of the class as an argument. A simple program is intentionally taken to revise many concepts of C++ in a single program. 

Requirements

  • You should have a thorough knowledge of the C and C++ programming languages
  • You should know the features of OOP
  • You must the know understand function overloading and Inheritance
  • You should be comfortable with any IDE like CodeBlock or Eclipse or equivalent environment
  • You should have written a minimum of 50 programs in C++

Description

Most C++ programmers stay away from C++ templates due to their perplexed nature. The excuses against templates:

  • Hard to learn and adapt.
  • Compiler errors are vague, and very long
  • Not worth the effort.

As a result, beginning and advanced C++ programmers alike are finding themselves wrestling with templates, attempting to decide why their
code is handled unexpectedly. 

Although templates have been part of C++ for well over two decade, they still lead to misunderstanding, misuse, or controversy. At the same time, they are increasingly found to be powerful instruments for the development of cleaner, faster, and smarter software. Indeed, templates have become the cornerstone of several new C++ programming paradigms.

This course would demystify most of the concepts using animation

Who this course is for:

  • Those who are interested in learning advanced concepts of C++
  • Those who are unemployed and interested in learning industry requirements
  • Those who have finished C and C++ and want to sharpen their skill sets