Click to See Complete Forum and Search --> : Using 1 Class in Multiple Files


Driklyn
May 25th, 2008, 10:51 PM
I'm trying to create a class inside a header file so that all my files can access that 1 class and only use that one. This is what I have so far.

----------

Window.h:

class Window
{
public:
Window();
~Window();

/* FUNCTIONS */
HWND OpenWindow(LPCTSTR, int, int);

/* VARIABLES */
int IsRunning;
};

typedef class Window *WINDOW;

----------

Main.h:

class Main
{
public:
Main();
~Main();

WINDOW GameWindow;
};

Main::Main()
{
Main::GameWindow = new Window();
}

typedef class Main *MAIN;

----------

The above code works and lets me call Main::GameWindow in every file but that's as far as I can go. I can't call Main::GameWindow->OpenWindow(). How do I fix this?

Notsosuperhero
May 25th, 2008, 11:04 PM
Are you including the proper headers?
Forward declarations may help.

When you put

Main::GameWindow->OpenWindow()
Or is 'Main' just a placeholder for a class object of type Main?

I'm not understanding the problem here. Do you get an error?

Driklyn
May 25th, 2008, 11:52 PM
If I try to use Main::GameWindow->OpenWindow() it gives me an error, but Main::GameWindow works. It's like it can see the functions inside of GameWindow for some reason. This guy on this other forum suggested I use "static WINDOW GameWindow" in Main.h but when I do that I get this error:

error LNK2001: unresolved external symbol "public: static class Window * Main::GameWindow" (?GameWindow@Main@@2PAVWindow@@A)

Driklyn
May 26th, 2008, 12:27 AM
Nevermind, I solved it. I was trying to initialize GameWindow inside the constructor of Main() and this was causing that error. I just had to move it outside the constructor and it worked...