C++ classes question

Hi all,

I’m currently working with C++ classes for the first time and trying to get the hang of them and need some help. I want to create a class which can have objects added to it, so I can perform actions on those objects part of that class.

Sorta like this:

drink is a class
liquid is a class

drink * Johns = new drink; // Makes a new drink called Johns
liquid * water = new liquid;
Johns->addLiquid(water); // Adds a liquid object to that class
Johns->emptyDrink; // Removes all the liquids in 'Johns' drink 

I want something a bit like that for a library I’m making right now. I’m making a path finding library and I’ve got it all working but now I’m trying to turn my very crappy all old structures and functions code into a very cool looking OOP style library. My thoughts for how I should design the library are that it should allow for multiple maps and instances of the pathfinding engine so the user can make separate maps for different areas of different sizes, to improve speed.
So say for example: imagine a game with a very large level. There could one pathfinding map the size of the whole level which tells the NPC’s how to avoid things like large bodies of water or mountains and where tunnels and shortcuts are. Then there could be smaller pathfinding map’s used for each section of the level.

… not that it matters, just letting you know why I’d like to go for this design… and that there is a reason, and that I’m not just doing for it look cool.

So basically I need to design the library to work something like this:


#include "myPathFindingLibrary.h"

int main()
{
[COLOR=RoyalBlue]      // Make an instance of the pathfinding engine, call it myDevice.[/COLOR]
     PathFindingInstance * myDevice = newPathFindingDevice();

[COLOR=RoyalBlue]      // Make a map called myMap and add it to myDevice. [/COLOR]
     map * myMap = myDevice->addMap();
[COLOR=RoyalBlue]
     // Make 2 nodes and add them to myMap.[/COLOR]
     node * myNode_1 = myMap->addNode();
     node * myNode_2 = myMap->addNode();
[COLOR=RoyalBlue]
     // Link those 2 nodes.[/COLOR]
     linkNodes(myNode_1,myNode_2);

[COLOR=RoyalBlue]      // Find a path from myNode_1 to myNode_2[/COLOR]
     path * myPath = myMap->findPath(myNode_1,myNode_2);
     etc....
     

Ok, so my question is how do a design my classes to allow this type of use of my library, where objects are added to other larger objects. Is there a special design for the classes I should be doing or should I just add a ‘parent’ variable to everything to keep track or whats connected to what.

I’m sorry if this is bad question, I’m still only very new to C++ and just getting a hang on this. I’m making this for an application to Sydney Uni, through an ‘experienced programmers portfolio application’… I don’t have any confidence that my UAI from the HSC is going to be high enough to get in at Sydney Uni, so I figured I’d try to get in through using my programming skills… so if anyone helps me with this, you can sleep tonight knowing that your helping me get in Uni! :beam: