Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7595021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:34:01+00:00 2026-05-30T21:34:01+00:00

I have implemented a simple ostream and streambuf class. For some reason, it crashes

  • 0

I have implemented a simple ostream and streambuf class. For some reason, it crashes when I try to instantiate my AndroidLogOStream object.

Note: I have stlport_static in my Application.mk

class AndroidLogStreamBuf : public std::streambuf
    {
    public:
        inline AndroidLogStreamBuf() : std::streambuf()
        {
            //std::cout << "asdfg";

        }

        inline ~AndroidLogStreamBuf()
        {

        }



    };

    class AndroidLogOStream : public std::ostream
    {
    public:
        inline AndroidLogOStream() : std::ostream(&mBuf)
        {

        }

        inline ~AndroidLogOStream()
        {

        }

    private:
        AndroidLogStreamBuf mBuf;
    };

It’s barebones, and it runs fine on windows. It compiles fine on android, but it crashes for some reason. The last line it tries to execute is in _streambuf.c:46:

template <class _CharT, class _Traits>
locale
basic_streambuf<_CharT, _Traits>::pubimbue(const locale& __loc) {
  this->imbue(__loc);          <---- crash
  locale __tmp = _M_locale;
  _M_locale = __loc;
  return __tmp;
}

Granted I am still quite confused on iostreams, but it must be something wrong with the constructor, I suppose it is not valid?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:34:02+00:00Added an answer on May 30, 2026 at 9:34 pm

    In a constructor, the base class is initialized first, followed by all of the members. When you call the base class constructor std::ostream, you’re passing it the address of mBuf, which has not yet been constructed. Accessing an object that hasn’t yet been constructed has undefined behaviour.

    To get around this, you could redesign your classes as follows:

    class AndroidLogStreamBuf : public std::streambuf
    {
    public:
        AndroidLogStreamBuf() : std::streambuf()
        { }
    
        ~AndroidLogStreamBuf()
        { }
    };
    
    class AndroidLogOStream : public std::ostream
    {
    public:
        AndroidLogOStream(AndroidLogStreamBuf *buf) :
            std::ostream(buf),
            mBuf(buf)
        { }
    
        ~AndroidLogOStream()
        { }
    
    private:
        AndroidLogStreamBuf *mBuf;
    };
    
    class AndroidLogOStreamWithBuf
    {
    private:
        AndroidLogStreamBuf mBuf;
        AndroidLogOStream mStream;
    
    public:
        AndroidLogOStreamWithBuf() :
            mBuf(&mStream),
            mStream()
        { }
    
        virtual ~AndroidLogOStreamWithBuf()
        { }
    
        AndroidLogOStream& getOStream()
        {
            return mStream;
        }
    };
    

    Notice the order I’ve declared mBuf and mStream in AndroidLogOStreamWithBuf: the two fields will be initialized in that order, regardless of the order they appear in the constructor initializer list. As an aside, marking the member functions as inline in your original code was superfluous: when you define a member function within the class definition, it’s automatically marked as inlinable.

    Whether this is a sensible design for your system depends on how you’re intending to use these classes, but the answer is probably “no”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented a simple linux shell in c. Now, I am adding some
I have the simple class using auto-implemented properies: Public Class foo { public foo()
I have implemented a simple server-client script like this: Server: class Server(Protocol): def connectionMade(self):
I have implemented a simple linked list class and I would now like to
I am playing around with some graphics, and I have implemented simple camera movement
I have implemented a simple Composite pattern using SplObjectStorage, like the example above: class
I have implemented a simple file upload-download mechanism. When a user clicks a file
In our desktop application, we have implemented a simple search engine using an inverted
Very simple Qt GUI application: On the scene I have multiple circles implemented as
I have a simple form on a view page, implemented as a user control,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.