Please explain some concepts about Pointer & Class & Array Pointer

I read this code section from a tutorial, but I cannot understand it thoroughly. It is about Pointer & Class Pointer & Array Pointer.

This is it:
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
// pointer to classes example
#include <iostream>
using namespace std;

class CRectangle {
	private:
		int width, height;
	public:
		// prototype
		void set_values (int,int);
		// method
		int area (void) {
			return (width * height);
		}
};

// definion
void CRectangle :: set_values (int a, int b) {
	width = a;
	height = b;
}

void main () {
	CRectangle a, *b, *c;
	CRectangle * d = new CRectangle[2];
	//
	b = new CRectangle;
	c = &a;
	a.set_values(1,2);
	b -> set_values(3,4);
	d -> set_values(5,6);
	d[1].set_values(7,8);
	//
	cout << "a area: " << a.area() << endl;
	cout << "*b area: " << b -> area() << endl;
	cout << "*c area: " << c -> area() << endl;
	cout << "d[0] area: " << d[0].area() << endl;
	cout << "d[1] area: " << d[1].area() << endl;
	//
	delete[] d;
	delete b;	
}


I try to search google and understand some parts of this code. But when it contains many concepts (i.e. pointer, array, class) in the BOLD section, I cannot grasp the points. Many operators (*, ->, etc. ), and I failed to distinguish between them.

Please explain it for me, especially the section in BOLD.

BTW, I see the "new" operator is very different from java one, is it right?

Thanks for any help.
i guess there's no point of repeating this because this website have explained it clearly in the tutorial section.

http://cplusplus.com/doc/tutorial/arrays/
http://cplusplus.com/doc/tutorial/pointers/
http://cplusplus.com/doc/tutorial/dynamic/
http://cplusplus.com/doc/tutorial/classes/

edit:
that's just my opinion.
Last edited on
Hi blackcoder,

In fact, I've read these tutorial already, but I can grasp the main points to understand some difficult parts (in BOLD). Just some problems with newcomers.

Thank anyway.
Topic archived. No new replies allowed.