i tried the following code i found on the net and is perfectly working.
template<typename T,typename T2>
std::vector<T>& operator<<(std::vector<T>& v1, T2 t1){
v1.push_back(T(t1));
return v1;
}
but for me the argument t1 must be from type T and not T2. so my first question is: why when i do
std::vector<T>& operator<<(std::vector<T>& v1, ***T t1***) //instead of T2 t1
i have the following error: error: no match for 'operator<<' (operand types are 'std::vector >' and 'std::string {aka std::basic_string}')
my second question is a ligne 4 of the code: what does mean T(t1) ?
thanks a lot !
EDIT:
thanks for all your answers!
this is the code i was using to test and try to inderstand the function.
using namespace std;
template<typename T>
std::vector<T>& operator<<(std::vector<T>& v1, T t1){
v1.push_back(T(t1));
return v1;
}
int main() {
vector<string> s;
string s2(" hello ");
s << s2 ;
cout<< s[0];
return 0;}
so the T is string and v1 is of type vector(String) and t1 is of type String this is why i was wondering why removing typename T2 from template causes error even if the value_type is string for both