Access objects from .cpp other than main

Is there a way to access an object (or a pointer to an object) which was created inside main.cpp, from another .cpp file, for another class? Right now the way I've been doing it is passing the object as a parameter, but that only works if the function call is in main, and even that seems like there should be an easier way I can't come up with.

Pseudocode for what I mean:

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
  class Box
{
public:
    Box() {height = 1, width = 2}
    int height;
    int width;
};

int main()
{
    Box* cube = new Box;
}

Editor.h
1
2
3
4
5
class Editor
{
public:
    void changeBox();
};

Editor.cpp
1
2
3
4
5
6
#include "Editor.h"

void Editor::changeBox()
{
    cube->width = 0;  //this is where my problem occurs.
}


Now, my first thought was to change which class the method belonged to, such as putting changeBox in the Box class. Then I ran into where I needed access to two objects in one method, and just ended up passing them both as parameters. Is there a simpler way to do what I'm trying to accomplish?
So from my understanding of what I just read I should be using pointer to members? I've never heard of them, so I'm learning about it just now.
Topic archived. No new replies allowed.