130

While reading the documentation for boost::test, I came across the term "free function". What I understand is that a free function is any function that doesn't return anything (Its return type is void). But after reading further it seems that free functions also don't take any arguments. But I am not sure. These all are my assumptions. So could anybody define free function?

chwarr
  • 6,777
  • 1
  • 30
  • 57
Jame
  • 21,150
  • 37
  • 80
  • 107

1 Answers1

163

The term free function in C++ simply refers to non-member functions. Every function that is not a member function is a free function.

struct X {
    void f() {}               // not a free function
};
void g() {}                   // free function
int h(int, int) { return 1; } // also a free function
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
  • let's say we have our main function in a different file and inside it we need to call a free function , so what should I do to have free functions in some other file that I will include it later in my main file ?? I mean should I make a hpp file where my free function are implemented there ( as static inline functions maybe ) ? – Joy May 04 '12 at 08:34
  • 5
    Usually you would declare them in a header file and implement them in a separate source file (with some exceptions like template functions). It would be better to open a new question on that specific topic though so people can answer you with more detail etc. – Georg Fritzsche May 04 '12 at 13:23