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?
1 Answer
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
-
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 ) ?– JoyCommented May 4, 2012 at 8:34
-
7Usually 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. Commented May 4, 2012 at 13:23