将多个参数传递给函数的优雅方式 [英] Elegant way to pass multiple arguments to a function

查看:281
本文介绍了将多个参数传递给函数的优雅方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似这样的函数:

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

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

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?

推荐答案

如果所有这些参数都有意义相关,请将它们包装在结构中。

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

这篇关于将多个参数传递给函数的优雅方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆