How class point to another class ?

Hi there,

I want to create a class called Train and class classed Car. The Train class represent whole train:
contain pointer to engine and car class for each train car with cargo weight and pointer to next car so we can access each car.

Create train new() space for train class with a constructor.
create new() 3 cars and give them weight value. Insert the car into train as it created and each car point to next one.

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
  
#ifndef TRAIN_H
#define TRAIN_H

class Train
{
	
	private:
		int* car;
  	public:
   		Train()
   		{
   			car = new int[3];
   		}

   		~Train()
   		{
   			delete [] car;
   		}
};

class car
{

	private:
	  	int car_weight;	
	public:

		car obj;
		car* ptr;
		ptr = &obj;

		int cargo_weight;
		int wieght;
		car()
		{
			int* firstCar = new int[3]; 
		}

		~car()
		{
			delete []firstCar;
		}
		
		car* Next;


};

#endif
int* car;
explain
Topic archived. No new replies allowed.