Create a ostringstream like class.
I'm creating a class to handle timed message dialogues on screen for my game, it all went well, but what I'm trying to achieve is something like a std::ostringstream object class, but with another abilities.
Code:
#include "cMessage.h"
cMessage::cMessage(int X, int Y, int ID) : X(X), Y(Y), FontID(ID)
{
StartTime = 0;
Active = false;
}
void cMessage::PostMessage(std::string Message)
{
StartTime = SDL_GetTicks();
this -> Message = Message;
Active = true;
}
void cMessage::OnWrite(SDL_Surface *Surf_Display, SDL_Surface *Surf_Balloon)
{
if(Surf_Display == NULL || !Active || Surf_Balloon == NULL)
return;
if(StartTime + MESSAGE_DURATION > SDL_GetTicks())
{
CSurface::OnDraw(Surf_Display, Surf_Balloon, BALLOON_X, BALLOON_Y);
SDL_Color Fg = {0, 0, 0, 0};
CFont::FontControl.OnWrite(&Surf_Display, Message.c_str(), FontID, X, Y, &Fg, NULL, CFONT_BLENDED | CFONT_ALIGN_CENTER);
}
else
{
Message.clear();
Active = false;
}
}
With this class, each time I want to post a message, I need to:
1. Create an otringstream object
2. Post this ostringstream message object with PostMessage()
How can I make a function that works like ostringstream, but that directly activate my message?
Like this PostMessage << "Message";
I'm really new to C++, so I don't have too much experience with operator overloadings.