Question: 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

Answer: 
Use an object and [lock it](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/lock-statement)

```
class App
{
    public delegate void StopHandler();
    public event StopHandler OnStop;
    private object keepAliveLock = new object();
    private bool keepAlive = true;

....
    private void Update()
    {
        int counter = 0;

        while (true)
        {
            lock(keepAliveLock)
            {
                 if(!keepAlive) 
                      break;
            }
            counter++;

            Console.WriteLine(string.Format("[{0}] Update #{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), counter));

            Thread.Sleep(3000);
        }
    }
}

```

Please note, that every access to keepAlive needs to be locked (surround by lock statement). Take care of deadlock situations.
I would personally change this from waiting for a bool to become false to use the ManualResetEvent. Also use a System.Timers.Timer for the update rather than a loop:

```
private ManualResetEvent WaitForExit;
private ManualResetEvent WaitForStop;

public App()
{
    WaitForExit = new ManualResetEvent(false);
    WaitForStop = new ManualResetEvent(false);

    new Thread(() => CheckForStop()).Start();
    new Thread(() => Update()).Start();

    WaitForExit.WaitOne();
}

private void CheckForStop()
{
    while (true) 
        if (Console.ReadKey().Key.Equals(ConsoleKey.Enter)) 
        {
            WaitForStop.Set();
            break;
        }
}

private void Update()
{
    int counter = 0;

    Timer timer = new Timer(3000);
    timer.Elapsed += Timer_Elapsed;
    timer.AutoReset = true;
    timer.Start();

    WaitForStop.WaitOne();

    timer.Stop();

    WaitForExit.Set();
}

private int counter = 1;
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
    Console.WriteLine(string.Format("[{0}] Update #{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), counter++));
}

```