Is it possible to edit an object that has not yet been defined in a function? For example, if I had a class in one file that adds one to a number:
class MyClass
{
    private:
       int i;
    public:
        MyClass()
        {
            i = 0;
        }
        int addOne()
        {
            i += 1;
            return i;
        }
};
And in another file, the class is imported. When the add function is called it calls the addOne function from the class:
#include "MyClass.h"
void add()
{
    a.addOne();
}
int main()
{
    MyClass a;
    add();
    return 0;
}
When I compile this it returns the error
error: ‘a’ was not declared in this scope
Is there any way for this to work?
Sites I read but didn't help solve my problem:
 
     
    