Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is standalone function? [duplicate]

Tags:

c++

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?

like image 634
Rex Rau Avatar asked Oct 09 '12 06:10

Rex Rau


People also ask

What is a stand-alone function?

A standalone function is a function (a subprogram that returns a single value) that is stored in the database. Note: A standalone function that you create with the CREATE FUNCTION statement differs from a function that you declare and define in a PL/SQL block or package.

What is a stand-alone statement C++?

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 ) { <...> }

Does C++ support stand-alone functions?

There are two types of functions in C++: stand-alone functions and member functions.


3 Answers

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 );
like image 92
SingerOfTheFall Avatar answered Sep 17 '22 19:09

SingerOfTheFall


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.

like image 20
iammilind Avatar answered Sep 20 '22 19:09

iammilind


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.

like image 44
Nawaz Avatar answered Sep 16 '22 19:09

Nawaz