Declaring a static class and accessing it

This topic is 4554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Share on other sites
Hi bud,

If i understand you correctly then congrats on getting something working in WIN32, it's a nightmare.

Regarding your question, i wouldn't bother with trying to share a window object between several classes. Just 'new' a new one whenever you need to. Atleast for now anyways, get your program working before you try to make it work better.

Hope that helps,

Dave

Share on other sites
Quote:
 Original post by DaveHi bud,If i understand you correctly then congrats on getting something working in WIN32, it's a nightmare.Regarding your question, i wouldn't bother with trying to share a window object between several classes. Just 'new' a new one whenever you need to. Atleast for now anyways, get your program working before you try to make it work better.Hope that helps,Dave

Haha, yeah Win32 is a pain. Thanks for the answer, but the way my program is designed needs to have a static class, or something to that effect.

Share on other sites
How would the singleton pattern fit this scenario?

Dave

Share on other sites
Try this:-

Main.h
CLoginWindow g_LoginWindow;static CLoginWindow* g_pLoginWindow = &g_LoginWindow;

I hope that helps [smile]

Share on other sites
I tried that. Seemed like it would work until it returned the same error of:

error C2146: syntax error : missing ';' before identifier 'g_Login'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assume

Share on other sites
Hi,

It looks as if the LoginWindow class is not known at the time you instantiate it. Did you check if it's header file is included ?

kind regards
Uncle Remus

Share on other sites
This is my current code in those modules:

Main.h
#ifndef __MAIN_H#define __MAIN_H#pragma comment(lib, "comctl32.lib")#pragma comment(lib, "wsock32.lib")#define WIN32_LEAN_AND_MEAN//#define ISOLATION_AWARE_ENABLED	1#include <windows.h>#include <commctrl.h>#include <shellapi.h>#include <stdio.h>#include <malloc.h>#include "login.h"#define WM_SOCKET_ASYNC			WM_USER + 100static bool bConnected = false; // Connected... or not =Pvoid CenterOnScreen(HWND hWnd, RECT Client);bool IsFileExist(LPSTR lpszFileName);LoginWindow g_Login;static LoginWindow* g_pLogin = &g_Login;#endif

#ifndef __LOGIN_H#define __LOGIN_H#include "main.h"class LoginWindow{public:	bool CreateLoginWindow();	void DestroyLoginWindow();	HWND GetWindow() const;	bool IsCreated() const;};#endif

Share on other sites
I think I have it working now. I'm still experimenting. I have create a new header file with all the statics. To avoid an include loopback error, I have referenced the new header to all the class header files and main.h. each class header refers to main.h as well. I'm still fiddling with it but so far it's looking promising and I have created some windows already so there's no compile errors... yet. Thanks for all your help so far guys!

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 10
• 9
• 9
• 10
• Forum Statistics

• Total Topics
631751
• Total Posts
3002087
×