Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Template Terminology

Tags:

c++

If I have the following

template<class T> print_all(vector<T> const & collection);

What would you call T in context of the declaration? i.e. Would you say that T is the argument for vector const & collection? i.e It satisfies a vector as the type is closed?

Keen to find out what the actual terminology is.

like image 803
Blair Davidson Avatar asked Jun 10 '13 12:06

Blair Davidson


People also ask

What is meant by template in C?

Templates are a feature of the C++ programming language that allows functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one.

Is template a keyword in C?

C++ template is also known as generic functions or classes which is a very powerful feature in C++. A keyword “template” in c++ is used for the template's syntax and angled bracket in a parameter (t), which defines the data type variable.

How many types of templates are there in C?

There are two types of templates in C++, function templates and class templates.

Why do we use templates in C?

A template is a simple yet very powerful tool in C++. The simple idea is to pass data type as a parameter so that we don't need to write the same code for different data types. For example, a software company may need to sort() for different data types.


1 Answers

T is a template parameter of the function template print_all, which is used as a template argument for the class template vector.

like image 97
Angew is no longer proud of SO Avatar answered Oct 22 '22 00:10

Angew is no longer proud of SO