What is a standalone function?

Possible duplicate:
What is the meaning of the term "free function" in C ++?

I'm not sure what a standalone function is.

Is it inside the class or the same as a normal function outside the main and class?

+4
source share
3 answers

A single function is just a normal function that is not a member of any class and is located in the global namespace. For example, this is a member function:

class SomeClass { public: SomeClass add( SomeClass other ); }; SomeClass::add( SomeClass other ) { <...> } 

And this is a separate one:

 SomeClass add( SomeClass one, SomeClass two ); 
+4
source

Usually standalone function

  • A global function that does not belong to any class or namespace .
  • Serves one purpose - to do something (for example, a utility, say strcpy() )

They should be used wisely, since too many of them will clutter up the code.

+3
source

A separate function is a function that is independent of any visible state:

 int max(int a, int b) { return a > b ? a : b; } 

Here max is a standalone function.

Autonomous functions have no state. In C ++, they are called free functions.

+3
source

Source: https://habr.com/ru/post/1438578/


All Articles