0

I am trying to define a function in c++,
I wrote it in main function.
I am getting an error : a function-definition is not allowed here before ‘{’ token}I have defined it as following :

float distance(float x, float y, float pitch)
     {
      float r;  //local variable
      r = sqrt(x * x + y * y);
      Bangle = arctan2(pitch*(y/r) + x , pitch*(x/r) -y);
      return (cos(Bangle),sin(Bangle));
     }

I dont know what dose this means. Any sugestion

2
Contributors
2
Replies
14
Views
1 Year
Discussion Span
Last Post by ALosh99
1

You can't define a function in a function in C++. (=nested function)
Bring it outside of the Main function and call it in Main if you wish.

0

you mean like this:

float distance(float x, float y, float pitch)
int main()
{
float r,x,y,Bangle,pitch;  
      r = sqrt(x * x + y * y);
      Bangle = atan2(pitch*(y/r) + x , pitch*(x/r) -y);
      return (cos(Bangle),sin(Bangle),pitch);


}

Edited by ALosh99

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.