Class Member Callback

Hi, im new programming in C++ and i got a problem with my 2 classes. First class was supposed to keep some data as well as calling a specific function member from a specific class when the function member "draw" was called. That specific function member should be defined only by the second class through "hDraw" that would be a private member except for the second class, of course. But when i try to call "hDraw" from the second class constructor, an error with Access Violation appears. What should i do? Below is my full code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
".h"

typedef struct
{
	short x;
	short y;
	short z;
} STR0, *PSTR0;

typedef struct
{
	short x;
	short y;
	short h;
	short w;
} STR1, *PSTR1;

typedef char *STR2;

class CLS1;

class CLS0
{
	public:
		CLS0(void)
		{
			pos.x = 0;
			pos.y = 0;
			pos.z = 0;
				
			rct.x = 0;
			rct.y = 0;
			rct.h = 0;
			rct.w = 0;

			pid = "NULL\0";

			drw = false;
			cmd = false;
			hdw = false;
		}

		STR0 getPosition(void)
		{
			return pos;
		}

		void setPosition(STR0 p)
		{
			pos.x = p.x;
			pos.y = p.y;
			pos.z = p.z;
		}

		STR1 getSize(void)
		{
			return rct;
		}

		void setSize(STR1 p)
		{
			rct.x = p.x;
			rct.y = p.y;
			rct.h = p.h;
			rct.w = p.w;
		}

		STR2 getName(void)
		{
			return pid;
		}

		void setName(STR2 p)
		{
			pid = p;
		}

		void draw(bool p)
		{
			drw = true;

			if (p) cmd = true;
			else cmd = false;

			if (hdw)
				(ph->*hw)(pos,rct,pid,cmd);
		}

		friend CLS1;

	private:
		void hDraw(void (CLS1::*h)(STR0,STR1,STR2,bool), CLS1 *hp)
		{
			ph = hp;
			hw = h;
			hdw = true;
		}

		STR0 pos;
		STR1 rct;
		STR2 pid;
		bool drw;
		bool cmd;
		bool hdw;
		CLS1 *ph;
		void (CLS1::*hw)(STR0,STR1,STR2,bool);
};

typedef CLS0 *PCLS0;

class CLS1
{
	public:
		CLS1()
		{
			conf.hDraw(&CLS1::buildFrame, this);
		}

	public:
		friend CLS0;
		CLS0 conf;

	private:
		void buildFrame(STR0 p1, STR1 p2, STR2 p3, bool p4)
		{
			std::cout << "Complete" << std::endl;
		}
};

typedef CLS1 *PCLS1;


".cpp"

int main(void) 
{
	CLS1 win
	win.conf.draw(true);

	system("PAUSE");

	return 0;
}
Last edited on
Line 87: friend CLS1; add 'class' : friend class CLS1;
yes indeed.... now works... thx
Topic archived. No new replies allowed.