Functor
Posted by Unknown in C++ Concept on 2009/12/12
Functor 譯名:仿函式
可以想成一個封裝成object 的函式
目的是為了提供更具彈性的寫法
simply functor example:
可以想成一個封裝成object 的函式
目的是為了提供更具彈性的寫法
simply functor example:
class FUNCTOR_NAME {
public:
RETURN_TYPE operator () ( OPERATOR_OVERLOADING_PARAMETERS)
{
//do action;
}
};
//you can design another function use it like
tempate< typename T1,class T2 >
void travel(T1 container ,T2 functor){
for_each(container.begin() , container.end , functor );
}
This entry was posted on 2009/12/12 at 晚上11:58 and is filed under C++ Concept. You can follow any responses to this entry through the RSS 2.0. You can leave a response.
- No comments yet.