What is the principle of a template in C ++?

And what template library should a new user be?

Not sure if OS matters, I'm talking about Windows if that matters.

+3
source share
4 answers

For beginners, it's best to start with a good book . The standard library (often also called STL) is the template library you should start with.

+3
source

Templates are general programming. The concept is this: you define the body / class of a function that will work with any data (having some properties, like a specific operator). Suppose you write a function that will return a summation of its given parameters:

int sum(int a, int b)
{
    return a + b;
}

, . :

std::string s1 = "abc", s2 = "def";
std::string s = sum(s1, s2);

sum() sum(). . sum() :

template<typename T>
T sum(const T& a, const T& b)
{
    return a + b;
}

sum() , operator+.

STL ( ), ++.

+5

- ++ ++. - . , ; .

, , - . , , , ; , , . T, T . , , T==int.

. ; ( ) std::list<T>. , , . std::list<float>, std::list<std::string> .. . - std::sort< > . qsort C, ++ , , std::sort< > .

ATL - Microsoft. , , , , Microsoft , . , COM-. ATL COM-; , COM-, .

+2

? , , " " " " (RAD), , , . std::list std::vector

, , , ( : pragram , ?), , boost / STL,

0

Source: https://habr.com/ru/post/1763565/


All Articles