In addition to what @dag is mentioned, the definition of a function without a parameter name finds its application in the specialized field. I know that you mentioned that there are no templates in the example you posted, but for completeness, I would like to publish this use case:
Suppose you define an erase
function for std
containers. But you want different erase_helper
do the actual work based on the type of container. A common and acceptable practice is to use traits
.
// Tags for containers struct vector_tag {}; struct map_tag {}; // Trait class template <typename C> struct container_traits; // Specialization of trait class template <typename T, typename A> struct container_traits<std::vector<T, A>> { typedef vector_tag category; }; template <typename K, typename V, typename C, typename A> struct container_traits<std::map<K, V, C, A>> { typedef map_tag category; }; // Helper function template <typename Container, typename X> void erase_helper(Container& c, const X& x, vector_tag) // <-- no param name { // Erase element from vector } template <typename Container, typename X> void erase_helper(Container& c, const X& x, map_tag) // <-- no param name { // Erase element from map } // Function interface template <typename Container, typename X> void erase(Container& c, const X& x) { erase_helper(c, x, typename container_traits<Container>::category()); }
Here you can see erase_helper
has a third parameter with no name. The parameter type tells the compiler to select the correct function in the template creation phase.
source share