This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// function_object.cpp | |
// CplusplusPractice | |
// | |
// Created by masai on 2015/05/22. | |
// Copyright (c) 2015年 masai. All rights reserved. | |
// | |
#include <iostream> | |
using namespace std; | |
// 10倍にして返す関数オブジェクト(このように定義すると、ヘッダーに処理内容も記述が可能) | |
class FunctionObject{ | |
public: | |
int operator()(int value){ | |
return value * 10; | |
} | |
}; | |
struct FunctionStructObject{ | |
int operator()(int value){ | |
return value * 20; | |
} | |
}; | |
int main(int argc, char* argv[]){ | |
FunctionObject obj; | |
cout << obj(5) << endl; | |
FunctionStructObject structObj; | |
cout << structObj(5) << endl; | |
} |
0 件のコメント:
コメントを投稿