티스토리 뷰
람다함수
C++ 11.0 부터 적용
1. 람다함수를 직접 실행됨.
1
2
3
4
5
6
7
8
9
10
11 |
#include "stdafx.h"
#include <iostream>
int main()
{
[] { std::cout << "Hello World" << std::endl; }();
std::cout << "Press any key...";
_gettchar();
return 0;
} |
cs |
<실행결과>
2. 함수 호출 방식
1
2
3
4
5
6
7
8
9
10
11 |
#include "stdafx.h"
#include <iostream>
int main()
{
auto func = [] { std::cout << "Hello World" << std::endl; };
func();
std::cout << "Press any key...";
_gettchar();
return 0;
} |
cs |
3. 람다함수에 인수 전달 <실행결과> 4. 반환값을 가지는 경우
함수호출 방식으로 실행결과는 위와 같음.
자료형 auto는 자동으로 지정된다. 6번 람다함수에서 리턴값이 없으므로 void형으로 지정된다.
cs
cs
<실행결>
http://blog.naver.com/PostView.nhn?blogId=psychoria&logNo=220398922456
http://blog.naver.com/PostView.nhn?blogId=drvoss&logNo=220340563782