Post: C++ help!
02-09-2013, 07:57 PM #1
|C++|
< ^ > < ^ >
(adsbygoogle = window.adsbygoogle || []).push({}); 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.
02-10-2013, 01:01 AM #2
Pichu
RIP PICHU.
Originally posted by SLiiTH3R View Post
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.
02-10-2013, 02:27 AM #3
Complete Speed
Do a barrel roll!
here's a good video of how to use abstract classes. i believe this might help you grasp a better understanding of it.
02-10-2013, 02:30 AM #4
Complete Speed
Do a barrel roll!
Originally posted by SLiiTH3R View Post
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.


forgot to quote basically you can also go watch the c++ classes that outofmylaboratory shows they're really good examples.
02-11-2013, 04:33 PM #5
ThyagoPS3
Little One
Originally posted by SLiiTH3R View Post
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 talking about Polymorphism? If so, then watch this video here:
02-12-2013, 03:16 PM #6
If you use YouTube and You must login or register to view this content. you will find a lot of information on classes and objects in C++.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo