c++ - 将多个参数传递给函数的优雅方式

标签 c++ function argument-passing

我有一个看起来像这样的函数:

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);

在我看来,它看起来很丑。处理这个问题的正确方法是什么?我应该创建几个具有不同数据类型(int、string 和 bool)的 vector 并将它们作为参数传递给这个函数吗?

最佳答案

如果所有这些参数都有意义相关,请将它们打包到一个结构中。

关于c++ - 将多个参数传递给函数的优雅方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24952190/

相关文章:

c++ - eclipse CDT : How to manage multiple main() functions in a single C++ project?

c++ - 从另一个 HBITMAP 复制位图

c++ - 共享对象工厂的设计模式

python - 如何在不多次调用函数的情况下访问函数内、函数外生成的字典。 PYTHON

c++ - fatal error 与非 fatal error 的区别

javascript - 访问有关导致 indexedDB 中请求出错的数据对象的信息

JavaScript setInterval 函数可能有参数,也可能没有参数

c++ - 使用相同的参数名称和成员名称是否有效

c# - 如何将任意方法(或委托(delegate))作为参数传递给函数?

c - 将数组传递给具有奇数格式的函数 - "v+last+1"