![]() |
In C++, we have multiple options to operate over the data like in the case where we can use functions and functors. Although both seem to be similar in a few ways but have multiple differences between them. Let’s check the differences between functions and functors in C++. What are functions?Functions are pieces of code that can be called from any other part of a program. They are a way of organizing code so that it is reusable, and can be used to perform a specific set of operations. Functions can be defined in any programming language and are typically used to encapsulate a set of instructions that can be called multiple times. Example: C++
Output
11 What are functors?Functors, also known as function objects, are objects that behave like functions. They are a type of object that can be treated like a function and can be used to encapsulate a set of instructions. They are similar to functions in that they can be used to encapsulate a set of operations, but they are different in that they can store states and can be used in more complex ways. Example: C++
Output
11 Difference between functions and functors
|
Reffered: https://www.geeksforgeeks.org
C++ |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |