CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2006
    Posts
    103

    having troubles with a stream...

    This constructor is causing the application to crash on Mac OS X, in
    xcode...
    Code:
    dbgFile::dbgFile(void) : std::ostream(0), output_buffer(),indent_buffer(&output_buffer), isopen(false) {}
    here is part of the class definition:
    Code:
    class dbgFile : public std::ostream {
    private:
        std::filebuf output_buffer;
        dbgBuf indent_buffer;
        std::stack<std::string> s;
        int stack_level;
        bool isopen;
    
    }
    I suspect that std:stream(0) is the culprit, but not sure how to
    tell...
    Last edited by JustSomeGuy; August 10th, 2009 at 12:18 PM.

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: having troubles with a stream...

    std:: ostream doesn't have a constructor that takes an int. What it does have is a constructor that takes a char *. 0 can be converted to a char * but dereferencing a null pointer usually crashes an application.
    use
    Code:
    dbgFile::dbgFile(void) : std::ostream(), output_buffer(),indent_buffer(&output_buffer), isopen(false) {}
    Kurt

  3. #3
    Join Date
    Nov 2006
    Posts
    103

    Re: having troubles with a stream...

    dbg is an instance of dbgFile

    however the first call to
    dbg << "A Message" << std::endl;

    causes a segmentation fault.

    The debugger shows:

    0 std:string::_M_write
    1 std:perator<< <std::char_traits<char> >
    2 main

  4. #4
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: having troubles with a stream...

    I don't understand your previous post.
    BTW you shouldn't inherit from any of the stream classes. ( they don't have a vitual destructor ).
    Use composition instead.
    Kurt

  5. #5
    Join Date
    Nov 2006
    Posts
    103

    Re: having troubles with a stream...

    Could you elaborate please? What is composition?

    do you mean:
    Code:
    class dbgFile : public std::ostream {
    private:
        std::filebuf output_buffer;
    needs to change to:
    Code:
    class dbgFile {
    private:
       std::ostream os;
       std::filebuf output_buffer;
    Last edited by JustSomeGuy; August 10th, 2009 at 01:48 PM. Reason: thinking....

  6. #6
    Join Date
    Nov 2006
    Posts
    103

    Re: having troubles with a stream...

    I just don't get it... This code works in some environments but not in others...
    I've attached the source... If anyone has time to look, that would be great.
    I'm on MAC OS X, 10.5.7 using XCode 3.1.2
    Attached Files Attached Files

  7. #7
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: having troubles with a stream...

    Code:
    std::ostream(0)
    This is a null stream that accepts data but sends it nowhere. Sort of like a 'black hole' stream.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  8. #8
    Join Date
    Nov 2006
    Posts
    103

    Re: having troubles with a stream...

    The bit bucket.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured