Hello everyone, and I'm glad I found this forum. I am stuck in a bind and don't know where to go from here. I have a message class and a mailbox class. I need to be able to add messages into a virtual "mailbox" (mailbox.cpp), I have 75% of everything done, I just dont know how to implement a few of the remaining functions in the mailbox class, as seen below. I am a beginner at C++ and I'm sure if someone can help me get going, I can finish the rest. Thank you guys for the help, this is what I have written thus far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//main
#include <iostream>
#include <string>
#include "message.h"
#include "mailbox.h"
usingnamespace std;
int main()
{
message create("Fee","Fi");
create.append("This is a message...");
create.print();
mailbox box;
box.add_message(create);
}
In the mailbox.cpp class, I got started under the add_message (message m), but thats as far as I know what to do. I need to finish the remove_message and get_message functions as well. OK, I can change the member data for mailbox, I see what you're saying about that.
For now, all the messages will be packed together into one long string,which is the concatenation of all messages, since we don't yet know how to store a collection of message objects. You can tell where a new message starts by searching for a 'From:' at the beginning of a line. Thats correct, it should be message mailbox::get_message(int i) const;
That's where I run into trouble. I dont know how to tie in the message class with the mailbox class. I just mentally don't know how I would retrieve the message from the mailbox.
Alright, I got that much. I need to add a number to the message so when I remove and get the message, it will know which message to get. So how will I implement that? I have a feeling its like:
1 2 3 4
void mailbox::add_message(message m)
{
box += number+m.to_string();
}
but I can't get it to work. Any suggestions as to where to go?