+ 1
Templates string constructor
I don't understand because with template<class Iter> string(Iter begin, Iter end) constructor of the String Class Library I don't need to use the keyword "template<class Iter>", why??
1 Answer
+ 2
It's called template deduction.
A template function should know what types should be used before starting the function. But we don't have to specify every template arguments before using. If there's missing. The compiler will check from the function parameters and get their types.
In a nutshell, if we have a function:
template<class T>
void func<T>(T x).
You can call it with:
func(10)., rather than func<int>(10)
Because the compiler gets the type of parameter you passed, which is int.