Boost logo

Boost :

Subject: Re: [boost] using of circular_buffer
From: news.gmane.org (q3wolfi_at_[hidden])
Date: 2012-03-28 11:47:11


hey, this sollution compiles.

due to an error i dont knot if my last message has been sent so here a
shot overview;

when debugging, i got some errors. do i use the circurlar buffer wrong?

here is an short extraction of my implementation:

class Stringbuffer
{
public:
     Stringbuffer() : buffer(10) {}
     boost::circular_buffer<std::string> buffer;
};

in another class:
class ConsoleText
{
public:
// some declarations
private:
Stringbuffer *textBuffer;
}

then, on the constructor:

ConsoleText::ConsoleText()
{
     textBuffer = new Stringbuffer();
}

during the runtime i do this:

void ConsoleText::GetConsoleMessage(std::string message)
{
     textBuffer->buffer.push_front(message);
}

void ConsoleText::GetConsoleMessage(std::string message, int num)
{
     message += " : ";
     message += toString(num);
     textBuffer->buffer.push_front(message);
}

void ConsoleText::FormatOutput()
{
     outPutText = "";
     for (int i = 0; i < textBuffer->buffer.size(); i++)
     {
         outPutText += textBuffer->buffer.front();
         outPutText += "\n";
     }
}

now, as i've got from the documentation, the last entry of the buffer
will be overwritten, which just fits into my requirenments.

on this call:
textBuffer->buffer.push_front(message);

i'll get a segmantion fault, which is an indicator of that textBuffer
wasn't instantiated well.

but where's the problem, i don't see it. sorry - any ideas?

Am 3/28/2012 1:36 PM, schrieb Nelson, Erik - 2:
> news.gmane.org wrote on Tuesday, March 27, 2012 8:42 PM
>
>> i've defined it in a class after the private-modifier like this:
>
>> boost::circular_buffer<std::string> textBuffer(10);
>
>> (as take from the documentation)
>
>> but my compiler on minGW will throw an error. so, i guess i got something wrong in declaring a string-textbuffer with the lenght of 10?!
>
>> in the boost-docs there is following example:
>> boost::circular_buffer<int> cb(3);
>
> Usually you can't specify the constructor arguments at the point of declaration of a class member. Does something like this work?
>
> Class A
> {
> A() : textBuffer(10) {}
> boost::circular_buffer<std::string> textBuffer;
> };
>
> ----------------------------------------------------------------------
> This message w/attachments (message) is intended solely for the use of the intended recipient(s) and may contain information that is privileged, confidential or proprietary. If you are not an intended recipient, please notify the sender, and then please delete and destroy all copies and attachments, and be advised that any review or dissemination of, or the taking of any action in reliance on, the information contained in or attached to this message is prohibited.
> Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Sender. Subject to applicable law, Sender may intercept, monitor, review and retain e-communications (EC) traveling through its networks/systems and may produce any such EC to regulators, law enforcement, in litigation and as required by law.
> The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or free of errors or viruses.
>
> References to "Sender" are references to any subsidiary of Bank of America Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not Insured by Any Federal Government Agency. Attachments that are part of this EC may have additional important disclosures and disclaimers, which you should read. This message is subject to terms available at the following link:
> http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you consent to the foregoing.
>
> _______________________________________________
> Unsubscribe& other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk