First code: You're calling mainPage()
as if it belongs to the global scope. The way you've written your code, though, it actually belongs to your class foo
. My best bet is, because of the context, it assumes you're declaring an implicitly-int
function called mainPage()
inside of both minus()
and add()
, and therefore complaining about multiple definitions.
You probably meant to have those functions be members for foo
anyway, so try rewriting lines 5 and 11 as void foo::add() {
and void foo::minus() {
respectively.
Second code: When you have an inline function, it can't actually be linked like a normal function. As a result, any code that uses foo::mainPage() must be able to see its full source or you will get undefined refernece errors. In order to mitigate the errors, you would actually have to move your inline function to "foo.h".
On a side note, this code shows very bad flow. You're calling mainPage()
from add()
and you're calling add()
from mainpage. You're basically causing your function to recurse, possibly indefinetely, based on user input. It may be a much better idea to use a real loop inside of mainPage()
and just return normally from the other functions.