Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

OOP!

Name: Anonymous 2012-11-10 8:49

Is there a better way of going about this? Say we have a house. The house has a bunch of rooms. Each room has a bunch of desks. Each desk has a bunch of drawers. Each drawer has a bunch of folders. And each folder has a bunch of papers.

class Paper{
};

class Folder{
public:
vector<Paper> paper;
};

class Drawer{
public:
vector<Folder> folder;
}

.
.
.

class House{
public:
vector<Room> room
};

//To access the first paper in the first folder in the first drawer in the first desk in the first room of the house:
house.room[0].desk[0].drawer[0].folder[0].paper[0]

It works, but am I going about this the right way?

Name: Anonymous 2012-11-10 8:54

Just use a tree please, less hassle probably. At least use a function to make it readable. get_paper(room desk drawer folder paper)

Name: Anonymous 2012-11-10 8:54

All are "Containers" except the last one "Papers".

Name: Anonymous 2012-11-10 9:21

It's the "right" way insofar as we have no more information from which to judge your application. Given that it's a useless class assignment that doesn't do anything useful, yes, it'll work quite well.

Name: Anonymous 2012-11-10 10:33

if you absolutely had to access papers at the house level then yes

Don't change these.
Name: Email:
Entire Thread Thread List