草庐IT

printAll

全部标签

c++ - 构造函数和析构函数 - C++

我需要编写一个程序,在屏幕上(随机位置)打印100颗星星,然后星星慢慢消失——一个接一个。我不允许使用循环或递归。我试过使用构造函数和析构函数,但我无法让星星一个接一个地消失(而不是全部消失)。有什么想法吗?谢谢,李抱歉-忘了说我正在使用C++我当前的访问违反无用代码:classstar{intx;inty;public:star(){x=rand()%80;y=rand()%80;PaintcharOnRandomLocation('*',x,y);};~star(){PaintcharOnRandomLocation('',x,y);};};classprintAll{star*a

c++ - 从可变参数函数将函数应用于参数包的所有元素

这个问题在这里已经有了答案:variadictemplateparameterpackexpandingforfunctioncalls(2个答案)关闭4年前。考虑以下(不起作用!)示例:#includetemplatevoidprint(consttype&item){std::coutvoidprintall(consttypes&...items){print(items)...;}intmain(){printall(1,2,"hello");}这里我有一个函数print可以简单地打印出它的参数,还有一个可变参数函数printall可以接受一组参数。现在,我想做的是简单地让pr