|
-
May 25th, 2008, 10:51 PM
#1
Using 1 Class in Multiple Files
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?
Last edited by Driklyn; May 25th, 2008 at 10:53 PM.
-
May 25th, 2008, 11:04 PM
#2
Re: Using 1 Class in Multiple Files
Are you including the proper headers?
Forward declarations may help.
When you put
Code:
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?
-
May 25th, 2008, 11:52 PM
#3
Re: Using 1 Class in Multiple Files
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)
-
May 26th, 2008, 12:27 AM
#4
Re: Using 1 Class in Multiple Files
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|