본문 바로가기

Programing/c/c++

람다 샘플 코드



#include "stdafx.h"
#include <iostream>
#include <functional>
#include <string>

using namespace std;

function< void() > f()
{
 std::string str("abcd");

 return [=] { cout<< "hello, " << str << endl; };

}

int _tmain(int argc, _TCHAR* argv[])
{

 auto func = f();

 func();// 출력 결과 : hello, abcd

 f()(); // 출력 결과 : hello, abcd

 f(); //출력결과없음

 return 0;

}