1.

How Can A C++11 Thread Be Created With A Function Pointer?

Answer»

Just pass in the address of a function to the thread constructor. The thread will start executing the function immediately.

#include "stdafx.h"

#include <thread&GT;

#include <IOSTREAM>

using namespace STD;

VOID FireMissile()

{

cout << "Firing sidewinder MISSILE " << endl;

}

int main()

{

//Creating a thread with a function pointer

thread t1(FireMissile);

t1.join();

return 0;

}

Just pass in the address of a function to the thread constructor. The thread will start executing the function immediately.

#include "stdafx.h"

#include <thread>

#include <iostream>

using namespace std;

void FireMissile()

{

cout << "Firing sidewinder missile " << endl;

}

int main()

{

//Creating a thread with a function pointer

thread t1(FireMissile);

t1.join();

return 0;

}



Discussion

No Comment Found