问题描述
无论提供多少个参数,我都想创建一个在有序列表中显示其参数的函数。我想制作这个示例程序来对其进行测试,但是我无法使其工作,尝试多种方法。这是简单的测试程序(没有任何实现):
#include <iostream>
void list( ... ); //list() starts from 1 and ends with however many there are
void list0( ... ); //list0() starts from 1 and ends with however many there are
//minus 1,because the last option is marked with a zero
int main() {
int drink,stuff,place,final;
std::cout << "Which would you like?" << std::endl;
list("tea","coffee");
std::cin >> drink;
std::cout << "Which would you like to take?" << std::endl;
list0("milk","cream","sugar","nothing");
std::cin >> stuff;
std::cout << "Where will you be sitting?" << std::endl;
list("table 1","table 2","table 3");
std::cin >> place;
std::cout << "Would you like anything else?" << std::endl;
list0("yes","no");
std::cin >> final;
if (final == 1)
std::cout << "Too bad,Go sit down" << std::endl;
return 0;
}
/* other stuff */
Which would you like?
1 - tea
2 - coffee
1
Which would you like to take?
1 - milk
2 - cream
3 - sugar
0 - nothing
1
Where will you be sitting?
1 - table 1
2 - table 2
3 - table 3
2
Would you like anything else?
1 - yes
0 - no
0
我需要帮助的地方是确定实现。这可能需要重载,因此我尝试使用重载的运算符创建类,但无法确定如何使用可变数量的参数来定义函数。
如果对此问题有完全不同的解决方案,不需要任何类似的操作,或者是一种简单得多的技术(除了一遍又一遍地显式编写std::cout << "1 - ..." << std::endl;
之外),请说明一下,因为我需要某种实现。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)