+ Reply to Thread
Results 1 to 2 of 2

Thread: What is function object?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    49

    What is function object?

    Hi all,

    I am new comers in C++ and I am exploring STL.

    I want to know about function object. Can anybody provide me simple example of it?

    Thanks in advance.

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    109
    Hi,

    Here is simple example of function object:

    Code:
    void FunctionObject(std::string& pUserData)
    {
    	printf("Hello %s\n", pUserData.c_str()) ;
    }
    
    void TestFunctionObject()
    {
    	std::vector<std::string> nameList ;
    	
    	nameList.push_back("Laila") ;
    	nameList.push_back("Diana") ;
    	nameList.push_back("Helen") ;
    	nameList.push_back("Christian") ;
    
    	std::for_each(nameList.begin(), nameList.end(), FunctionObject) ;
    }
    Thanks

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts