-
nested classes
First, here is my code:
Code:
#include <iostream>
#include <string>
using namespace std;
class message {
public:
message();
~message();
string to;
string from;
string all;
class mailbox {
public:
void mailbox::add_message(message) {
// do something to store the string in a file
}
private:
};
private:
};
message::message() {
to = "to";
from = "from";
all = to + from;
// create a string with the message in it
}
message::~message() {
}
int main() {
message bob;
message::mailbox homer;
homer.add_message(bob);
}
Now what I want to do with this is have the message class create a message, and then have the mailbox class store that message. But I'm having problems trying to visualize how to move the information in the new message object to the mailbox. This may be a stupid question, but classes make my head spin, and I can't for the life of me make it do what I want. Thanks in advance!
jim
-
You need to stop the spinning!
Read this page on object design, maybe it will slow the spin.
You should also design how everything will work before you start writting code, not vica-versa.
gg
-
You're dealing with a has-a relationship, but doing it in reverse. A mailbox has messages in it. A message does not have mailboxes in it. What you are doing is sort of like doing this:
Code:
// a door containing a bunch of houses
class Door {
class House {
//...
};
};
when you want to be doing this:
Code:
// a house containing a bunch of door
class House {
class Door {
//...
};
};
Follow that link codeplug gave you. It should help clear the fog of war.
(100 posts!)