Pointers

Hello
I want someone to explain what function would be called in each line in the following code, it a bit confusing and i would like some expert to show me what's being called in each line, for example Line 5 : function x is being called. why?

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
  
class Base
{
public:
	void F();
	virtual void G() = 0;
	virtual void H();
	virtual void I();
};


class D :public Base
{
public:
	virtual void F();
	void G();
	void H();
	virtual void J();
};

class E : public D
{
public:
	void F();
	void G();

};


int main()
{
	D* pD = new D;
	Base* pB = pD;
	E* pE = new E;


	pB->F();				//line 1
	pB->G();				//line 2
	pB->H();				//line 3
	pB->I();				//line 4

	pD->F();				//line 5
	pD->G();				//line 6
	pD->I();				//line 7
	pD->J();				//line 8

	pB = pE;
	pD = pE;

	pB->F();				//line 9
	pB->G();				//line 10
	pB->H();				//line 11
	pB->I();				//line 12

	pD->F();				//line 13
	pD->J();				//line 14

	pE->F();				//line 15
	pE->H();				//line 16

}
closed account (48T7M4Gy)
One very self-satisfying way to handle these sorts of problems is to modify the code above and add a few lines in the class methods to trace what's happening. All you need is a
std::cout << "Here we are at ????\n"; line in a few places.
:)
Topic archived. No new replies allowed.