Skip to content

Instantly share code, notes, and snippets.

@MasazI
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save MasazI/9920507c429a5a4f3465 to your computer and use it in GitHub Desktop.

Select an option

Save MasazI/9920507c429a5a4f3465 to your computer and use it in GitHub Desktop.
object_function.cpp
//
// 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment