Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elegant way to pass multiple arguments to a function

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?

like image 767
Tomasz Kasperczyk Avatar asked Jul 25 '14 09:07

Tomasz Kasperczyk


People also ask

How do you pass multiple parameters to a function?

Note that when you are working with multiple parameters, the function call must have the same number of arguments as there are parameters, and the arguments must be passed in the same order.


1 Answers

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

like image 171
Quentin Avatar answered Sep 24 '22 23:09

Quentin