This is a bit of a strange syntax in C ++, but if you are familiar with JS (for example), you may be aware of the concept of a method chain. It is a bit like this.
add_options() returns an object with operator() . The second line calls operator() object returned by the first line. The method returns a reference to the original object, so you can continue to call operator() many times in a row.
Here is a simplified version of how it works:
#include <iostream> class Example { public: Example & operator()(std::string arg) { std::cout << "added option: " << arg << "\n"; return *this; } Example & add_options() { return *this; } }; int main() { Example desc; desc.add_options() ("first") ("second") ("third"); return 0; }
As noted in gbjbaanb's comments, this is actually very similar to how the assignment chain a = b = c = 0 works for classes. It also looks like behavior that is often taken for granted when using ostream::operator<< : you expect to be able to do std::cout << "string 1" << "string 2" << "string 3" .
source share