class MyClass
{
int x, y;
public:
void myProblem(int x, int y);
};
void MyClass::myProblem(int x, int y)
{
if( x == y)
{
std::cout << "You win!"
//what do i put here to exit the class and go straight to the main
//instead of moving on through the program?
}
else
{
//some other code
}
}
First off, that's not a void member function, it's a constructor for your MyClass class and is called implicitly whenever a MyClass object is creative.
Second, the x and y values will always be uninitialised here, so that if statement isn't going to sanely check anything.
Finally, if you had a member function and called it then once the function exits scope it you'll return to the point from where it was called.
i edited it... What Im trying to do is play tic tac toe, and if the user gets 3 in a row, then exit the program (which is tested inside a void member function), if not, keep playing the game
doesnt work. if i do that, it just gets out of the member function, but still moves on through the program... it feels like i need to step out of each function and test if the return is true in each case to get out of it...
EDIT:
Got it to work thanks! Just needed to return it in the preceding function that called it