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?
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?
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 );
A stand-alone function is typically
class
or namespace
.strcpy()
)They should be used judiciously as too much of those will clutter the code.
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.