Here is my error message:
Warning 1 warning C4717: 'getx' : recursive on all control paths, function will cause runtime stack overflow
and here is my code I will Bold the part that is giving me problems!
Can anyone help me please?!?!?!?!
class point
{
public:
point();
point(int xx, int yy);
friend double distance(point p1, point p2);
int getx();
int gety();
double dist;
double xnum, ynum, total;
When your code calls getx(), it jumps to the getx() function and executes whatever's in the function. When it gets to a return statement, it jumps back to whatever comes straight after the function call. But, your getx() and gety() functions call themselves infinitely. Because every time you call a function it uses a little bit of memory, this function will eventually want more memory than the operating system will give it, resulting in stack overflow.
so how would I go about fixing that? Can I add a break after the return statement, and if I do add a break will it still allow me to get two values?
Or do I need to use a while statement, so it will only take values that the user input?
#include "quiz2.h"
usingnamespace std;
int main()
{
point c;
int x , xx;
int y, yy;
cout <<"Enter two points: ";
cin >> x >> xx;
c.getx();
cout <<"Enter two points: ";
cin >> y >> yy;
c.gety();
cout <<"***** The distance between (x1, y1) and (x2, y2) is: " <<c.dist <<"*****" <<endl;
system("pause");
return 0;
}
basically you're not setting the data stored in 'point c' to anything. In class point you need to define another 2 functions, void setx (int) and void sety (int) so that you can actually store data in the class.