添加对递归函数的控制 [英] Add control over recursive function

查看:67
本文介绍了添加对递归函数的控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,下面我附上了一个代码,我需要一个关于递归函数的控件。意思是,它应该等待我的按钮按下信号进一步移动。



Hello All, below i attached a code where i need a control on recursive function. Means, it should wait for my button press signal to move further.

void PlaySongs::performance(int step){

step++;

if (waitForInterruptSys (iOnePin, -1) >0)
{
   cout<<"Push Button is pressed"<<endl;

   SoundNamespace::SoundProject::SoundProject project;

   project.Init();
   project.InitSound();
   
   project.StartInterruptThreads();
   project.LoadProject();
   project.AdjustSounds();
   project.LoadSounds(true);
   project.StartPlayingSounds();
   
   cout << "Initialization finished." << endl;

// Some C++ control statement NEEDS here  <--

/* here i need control, so that, after button pressed on bread board, it should move further i.e. perform next statements, otherwise wait infinite time. something like cvWaitKey(0) from opencv. Interrupt detected by (waitForInterruptSys (iOnePin, -1) >0). like written above. */

if(step==3)
     return;
else
    performance(step);

}





我试过





I tried

int first = std::cin.get();
std::cin.ignore(256, 'waitForInterruptSys (iOnePin, -1) >0');   ---> NOt sure, because i don't why std:: is not detecting ignore function and not at all confident on second parameter of ignore function



任何人都可以推荐一些东西?在此先感谢。


Anybody can suggest something ?? Thanks in advance.

推荐答案

如果(waitForInterruptSys(iOnePin,-1)表示按下按钮,请将 if 语句更改为a while 声明...



If "(waitForInterruptSys (iOnePin, -1)" represents your button press, change the if statement to a while statement ...

if (waitForInterruptSys (iOnePin, -1) >0)
{
   cout<<"Push Button is pressed"<<endl;





...变成......





... becomes ...

while (waitForInterruptSys (iOnePin, -1) <= 0) NULL;
cout<<"Push Button is pressed"<<endl;





NULL只是一个占位符,因为while语句(如if)需要一个语句。这有效地说while(没有按下按钮)什么都不做。



The "NULL" is just a placeholder since the while statement (like the if) expects a statement to follow. This effectively says "while (no button is pressed) do nothing".


这篇关于添加对递归函数的控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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