#include <iostream>
#include <vector>
#include <functional>
using namespace std;
//C++ 11에서 지원하는 using을 이용하여 별칭 만들기
using customInt = int; /*<-*/ typedef int customInt1;
using vi = vector<int>; /*<-*/ typedef vector<int> vi1;
//Test Print
void print(int index)
{
cout << "print "<<index<<"\n";
}
int main()
{
//예시는 void (int)에 대하여 함수 포인터 작성
//기초적인 typedef -> (typedef 반환형(*변수이름)(매개변수);)
typedef void(*fp1)(int);
fp1 func1 = print;
func1(1);
//C++ 11에서 지원하는 using을 이용한 함수 포인터 -> (using 변수이름 = 반환형(*)(매개변수);)
using fp2 = void(*)(int);
fp2 func2 = print;
func2(2);
//C++ 11에서의 std::function
//#include <functional> 필수
//std::function<반환값(매개변수)> 변수이름
std::function<void(int)> func3;
func3 = print;
func3(3);
return 0;
}
'C++' 카테고리의 다른 글
C++ Linked List (0) | 2024.12.07 |
---|---|
OpenGL : Laplacian Smoothing & Taubin Smoothing (0) | 2024.11.24 |
cout 소수점 고정 (0) | 2024.11.24 |
string::find (0) | 2024.11.24 |
STL : sort algorithm (0) | 2024.11.24 |