Elegant way to pass multiple arguments to a function

Tomasz Kasperczyk picture Tomasz Kasperczyk · Jul 25, 2014 · Viewed 18.5k times · Source

I've got a function which looks like this:

bool generate_script (bool net, bool tv, bool phone,
                        std::string clientsID,
                        std::string password,
                        int index, std::string number, 
                        std::string Iport, std::string sernoID,
                        std::string VoiP_number, std::string  VoiP_pass,
                        std::string target, int slot, int port, 
                        int onu, int extra, std::string IP, std::string MAC);

In my opinion it looks ugly. What is the proper way of handling this problem? Should I create few vectors with different data types (int, string and bool) and pass them as arguments to this function?

Answer

Quentin picture Quentin · Jul 25, 2014

If all these parameters are meaningfully related, pack them in a structure.