Connoisseurs C ++

I know that in C ++ the function call is possible only after its actual declaration. But what if this situation:

There are 2 functions, one can recursively activate the other.

double Meth1() { {...} if (...) return Meth1(); else return (Meth2()); } double Meth2() { {...} if (...) return Meth2(); else return (Meth1()); } 

The compiler curses the Meth2 () call in the Meth1 function, since it is not actually declared. How can you clearly indicate such a case?

  • Yes, I tried to find information myself. If addressed here, then did not find! I don’t need this advice! - Khetag Abramov
  • And what a strange extra brackets in some return ? - AnT
  • Indeed , superfluous =) - Khetag Abramov

1 answer 1

Use advance announcement

 double Meth2(); //forward declaration, прототип должен совпадать double Meth1() { return Meth2(); //уже используем } double Meth2() // а теперь рассчитаемся с компилятором { ... } 

And here is the link for classes (section Forward declaration)