Auto get()s and set()s

C

Chris Yates

Hello, why wont this work?

#define MAKEGET(t, n) t get##n() const { return this->n; }
#define MAKESET(t, n) void set##n(const t n) { this->n = n; }
#define MAKEGETSET(t, n) MAKEGET(t, n) MAKESET(t, n)

class cSys
{
private:
HWND hWnd_Main;
HWND hWnd_Func;
HWND hWnd_FuncEdit;
HINSTANCE hInst;
public:
cSys(HINSTANCE hInstance);
MAKEGETSET(HWND, hWnd_FuncEdit);
MAKEGETSET(HINSTANCE, hInst);
};

cSys *sys;

sys = new cSys();

sys->sethWnd_Main((HWND)1);
HWND res = sys->gethWnd_Main();

It compiles okay, and the set method seems to work fine, but the get method
gives an access violation. Thanks.
 
J

Jack Klein

Hello, why wont this work?

#define MAKEGET(t, n) t get##n() const { return this->n; }
#define MAKESET(t, n) void set##n(const t n) { this->n = n; }
#define MAKEGETSET(t, n) MAKEGET(t, n) MAKESET(t, n)

class cSys
{
private:
HWND hWnd_Main;
HWND hWnd_Func;
HWND hWnd_FuncEdit;
HINSTANCE hInst;
public:
cSys(HINSTANCE hInstance);
MAKEGETSET(HWND, hWnd_FuncEdit);
MAKEGETSET(HINSTANCE, hInst);
};

cSys *sys;

sys = new cSys();

sys->sethWnd_Main((HWND)1);
HWND res = sys->gethWnd_Main();

It compiles okay, and the set method seems to work fine, but the get method
gives an access violation. Thanks.

Have you looked at the output generated by the preprocessor? What
does it look like?
 
C

Chris Yates

Actually, I don't think it's in the macros, because the following gives the
same error:
HWND gethWnd_FuncEdit() { return hWnd_FuncEdit; }

-
Chris
 
C

Chris Yates

Actually, I don't think it's in the macro's, because the following gives the
same error:
HWND gethWnd_FuncEdit() { return hWnd_FuncEdit; }

???

-
Chris
 
C

Chris Yates

I should have been more specific in my example, because I'm calling
sys->gethWnd_FuncEdit on the WM_CREATE message, which is when it seems to be
giving the access violation. The code works fine in the given example, but
for some reason the global class sys is unavailable in the callback function
during WM_CREATE. Any ideas why? Thanks!
-
Chris
 
P

Phlip

Chris said:
I should have been more specific in my example, because I'm calling
sys->gethWnd_FuncEdit on the WM_CREATE message, which is when it seems to be
giving the access violation. The code works fine in the given example, but
for some reason the global class sys is unavailable in the callback function
during WM_CREATE. Any ideas why? Thanks!

In general, if you are still stitching together your project's first window
and first global object, you really ought to write very simple code, and
read tutorials that show simple code in these quarters.

Depending on where your 'new' is, the WM_CREATE message might call before
it. If cSys is global then it will be NULL before it's assigned, and you can
test for that with 'if'.

Use http://groups.google.com to find a newsgroup that covers entry-level
Windows programming for help with the architecture here.
 
C

Chris Yates

I just realized I did something I knew not to do...write code that can break
in a constructor. Taking the CreateWindow() out of the constructor and into
an initWin() fixed the problem. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,966
Members
47,516
Latest member
ChrisHibbs

Latest Threads

Top