-5

I try do a recursive function in C++ when A is recursive and calls B, B calls A, but when is it compile, the compiler can't find one of the two function. Is normal in c++, but there a way to bypass this?

Edit : After read about forward declaration, I have solve this problem.

Ben47955
  • 1
  • 5

1 Answers1

0

Add the signature of the function at the begening of the code like that (Code is really junk):

void gererParenthese(vector<string> &expressionV, unsigned int &i);
gererParenthese(expressionV, i);

void gererParenthese(vector<string> &expressionV, unsigned int &i)
{
 if ((expressionV[i]).compare("(") == 0)
 {
  int nbrPa = 0;
  vector<string> tempo;
  do
  {
   i++;
   if ((expressionV[i]).compare("(") == 0)
   {
    nbrPa++;
   }
   else if ((expressionV[i]).compare(")") == 0)
   {
    nbrPa--;
   }

   tempo.push_back(expressionV[i]);
  } while (nbrPa != 0);
  tempo.pop_back();
  (expressionV[i]) = evaluer(tempo);
  i--;
 }
}


double evaluer(vector<string> expressionV)
{
 double resultat = 0;
 for (unsigned int i = 0; i < expressionV.size(); ++i)
 {
  if ((expressionV[i]).compare("(") == 0)
  {
   gererParenthese(expressionV, i);
  }
  else if ((expressionV[i]).compare("/") == 0)
  {
   int iT = i;
   gererParenthese(expressionV, i);
   
   double temp =atof((expressionV[i]).c_str());
   resultat = resultat /temp ;
   expressionV[i] = resultat;

  }
  else if ((expressionV[i]).compare("*") == 0)
  {
   int iT = i;
   gererParenthese(expressionV, i);
   double temp = atof((expressionV[i]).c_str());
   resultat = resultat * temp;
   expressionV[i] = resultat;
  }
  else if ((expressionV[i]).compare("-") == 0)
  {
   int iT = i;
   gererParenthese(expressionV, i);
   double temp = atof((expressionV[i]).c_str());
   resultat = resultat - temp;
   expressionV[i] = resultat;
  }
  else if ((expressionV[i]).compare("+") == 0)
  {
   int iT = i;
   gererParenthese(expressionV, i);
   double temp = atof((expressionV[i]).c_str());
   resultat = resultat + temp;
   expressionV[i] = resultat;
  }
  else
  {
   double temp = atof((expressionV[i]).c_str());
   resultat = temp;
  }

 }
 return resultat;
}
Ben47955
  • 1
  • 5