Originally posted by SLiiTH3R
I need help understanding the use of classes with other classes as member data. It is very convoluted to me in my book. They used an example of a point class(as in a point on a graph) and another class named rectangle. They used the point class in the rectangle class and created method functions in teh rectangle class of the type point. This example is very cryptic to me. Does anyone know of another source where i can grasp this topic of using classes with other classes as member data. I sort of grasp it conceptually, but without me understanding an example, i cant see myself effectively implementing it into my code in the future.
Are you confused by how to use classes in another class?
If so, a class is used to create an object. Without a class you can't create an object.
Say if I had the class "Zelda".
In C#/Java I'd do this:
Zelda zel = new Zelda();
I call the class name and create my object, zel. I use the initialize the class with the protected word "new" and call the class by using it as a function.
This idea will be the same for you.
Now, if I had inside the class the function "public void EatFish() {MessageBox.Show("No, I don't wanna"}"
I would use inside my main class where I created the zel object -> zel.EatFish();
I'm starting to learn C++ but I can't directly tell you how to write it without making mistakes. Hopefully this help clears you up a bit on the understanding.