I have a C ++ program that has free functions.
Since most of the team has little experience with object-oriented design and programming, I need to refrain from objects of functions.
I want to pass a function to another function, for example for_each. I usually use a function pointer as a parameter:
typedef void (*P_String_Processor)(const std::string& text);
void For_Each_String_In_Table(P_String_Processor p_string_function)
{
for (unsigned int i = 0; i < table_size; ++i)
{
p_string_function(table[i].text);
}
}
I want to remove pointers, as they can point anywhere and contain invalid content.
Is there a way to pass a function by reference, similar to passing by pointer, without using a function object?
Example:
typedef void (??????);
void For_Each_String_In_Table( string_function);
source
share