6

Possible Duplicate:
What is the meaning of the term “free function” in C++?

I am not sure what a standalone function is.

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

Community
  • 1
  • 1
Rex Rau
  • 103
  • 1
  • 1
  • 5
  • 7
    It's not a formal term. We've got a reasonable idea, but we'd probably call it a _free_ function. – MSalters Oct 09 '12 at 07:01

3 Answers3

6

A stand-alone function is just a normal function that is not a member of any class and is in a global namespace. For example, this is a member function:

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

And this is a stand-alone one:

SomeClass add( SomeClass one, SomeClass two );
SingerOfTheFall
  • 28,216
  • 8
  • 63
  • 102
3

A stand-alone function is typically

  • A global function which doesn't belong to any class or namespace.
  • Serves a single purpose of doing something (like a utility, say strcpy())

They should be used judiciously as too much of those will clutter the code.

iammilind
  • 65,167
  • 30
  • 162
  • 315
3

A standalone function is one which doesn't depend on any visible state:

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

Here max is a standalone function.

Standalone functions are stateless. In C++, they're referred to as free functions.

Nawaz
  • 341,464
  • 111
  • 648
  • 831