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

  • SEARCH
  • Home
  • 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 9188083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:55:41+00:00 2026-06-17T19:55:41+00:00

I have a c++ library that provides an object with complicated logic. During data

  • 0

I have a c++ library that provides an object with complicated logic. During data processing, this object outputs lots of things to std::cout (this is hardcoded now). I would like the processing output not to go to standard output but to a custm widget (some text displaying). I tried to create a std::ostream class member, set it with a parameter (std::cout for console application and some other ostream handled inside GUI application). But the compiler throws me following errors:

[ 14%] Building CXX object src/core/CMakeFiles/PietCore.dir/pvirtualmachine.cpp.o
/usr/include/c++/4.6/ostream: In constructor ‘PVirtualMachine::PVirtualMachine(QString)’:                                                                        
/usr/include/c++/4.6/ostream:363:7: error: ‘std::basic_ostream::basic_ostream() [with _CharT = char, _Traits = std::char_traits]’ is protected
/home/tomasz/Development/C++/piet/src/core/pvirtualmachine.cpp:33:50: error: within this context
In file included from /usr/include/c++/4.6/ios:45:0,
                 from /usr/include/c++/4.6/ostream:40,
                 from /usr/include/c++/4.6/iterator:64,
                 from /usr/include/qt4/QtCore/qlist.h:50,
                 from /usr/include/qt4/QtCore/qvector.h:48,
                 from /usr/include/qt4/QtGui/qpolygon.h:45,
                 from /usr/include/qt4/QtGui/qmatrix.h:45,
                 from /usr/include/qt4/QtGui/qtransform.h:44,
                 from /usr/include/qt4/QtGui/qimage.h:45,
                 from /usr/include/qt4/QtGui/QImage:1,
                 from /home/tomasz/Development/C++/piet/src/core/pcodepointer.h:17,
                 from /home/tomasz/Development/C++/piet/src/core/pblockmanager.h:9,
                 from /home/tomasz/Development/C++/piet/src/core/pvirtualmachine.h:10,
                 from /home/tomasz/Development/C++/piet/src/core/pvirtualmachine.cpp:4:
/usr/include/c++/4.6/bits/ios_base.h: In member function ‘std::basic_ios& std::basic_ios::operator=(const std::basic_ios&)’:
/usr/include/c++/4.6/bits/ios_base.h:791:5: error: ‘std::ios_base& std::ios_base::operator=(const std::ios_base&)’ is private
/usr/include/c++/4.6/bits/basic_ios.h:64:11: error: within this context
In file included from /usr/include/c++/4.6/iterator:64:0,
                 from /usr/include/qt4/QtCore/qlist.h:50,
                 from /usr/include/qt4/QtCore/qvector.h:48,
                 from /usr/include/qt4/QtGui/qpolygon.h:45,
                 from /usr/include/qt4/QtGui/qmatrix.h:45,
                 from /usr/include/qt4/QtGui/qtransform.h:44,
                 from /usr/include/qt4/QtGui/qimage.h:45,
                 from /usr/include/qt4/QtGui/QImage:1,
                 from /home/tomasz/Development/C++/piet/src/core/pcodepointer.h:17,
                 from /home/tomasz/Development/C++/piet/src/core/pblockmanager.h:9,
                 from /home/tomasz/Development/C++/piet/src/core/pvirtualmachine.h:10,
                 from /home/tomasz/Development/C++/piet/src/core/pvirtualmachine.cpp:4:
/usr/include/c++/4.6/ostream: In member function ‘std::basic_ostream& std::basic_ostream::operator=(const std::basic_ostream&)’:
/usr/include/c++/4.6/ostream:57:11: note: synthesized method ‘std::basic_ios& std::basic_ios::operator=(const std::basic_ios&)’ first required here 
/home/tomasz/Development/C++/piet/src/core/pvirtualmachine.cpp: In member function ‘void PVirtualMachine::setOutput(std::ostream)’:
/home/tomasz/Development/C++/piet/src/core/pvirtualmachine.cpp:216:11: note: synthesized method ‘std::basic_ostream& std::basic_ostream::operator=(const std::basic_ostream&)’ first required here

I’d be glad if someone pointed me out what is wrong, because I’ve got no idea…

My code looks like this:

  • .h file
class PVirtualMachine {
  private:
    std::ostream output;
    [...]
  public:
    void setOutput(std::ostream);
    [...]
};
  • .cpp file
void PVirtualMachine::setOutput(std::ostream os)
{
  output = os;
}
  • 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-06-17T19:55:42+00:00Added an answer on June 17, 2026 at 7:55 pm

    You’ve got two options here:

    • Use references, or
    • Use pointers

    You can’t use normal instances because ostream is non-copyable.

    Using references (direct reference to an already-instantiated ostream)

    class PVirtualMachine {
      private:
        std::ostream & output;
        [...]
      public:
        PVirtualMachine(std::ostream &);  // Reference must be initialized on construction.
        [...]
    };
    

    Advantages:

    • No pointer syntax.
    • Should always refer to a valid instance of std::ostream, as long as the original variable is not deleted.

    Disadvantages:

    • The PVirtualMachine class must be constructed with the output reference in the initialization list, otherwise it will not compile.
    • Cannot change the reference once it has been initialized.
    • Cannot work with move-assignment operators (i.e. operator=(PVirtualMachine &&))

    Using pointers (optional reference to object)

    class PVirtualMachine {
      private:
        std::ostream * output;
        [...]
      public:
        void setOutput(std::ostream *);
        [...]
    };
    

    Advantages:

    • Can be instantiated as a null pointer.
    • Can be passed around easily.
    • Can be updated to point to a new std::ostream instance.
    • Can be created internally or externally to the PVirtualMachine instance.
    • Works with move-assignment operator.

    Disadvantages:

    • Pointer syntax.
    • Must check for null references when accessing the ostream and/or in the constructor.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have a library that provides a method that accepts an object that
I have a C++ library that provides various classes for managing data. I have
I have a library that I created with some business logic that includes writing
I have a library that has several options defined as this: #define shouldShowToolbar YES
I have a cache library that stores cached data in normal php files, with
I have a library-provided function that runs a callback after some processing. Inside that
I am using a C++ library that provides an object that, for the sake
I have a C library that has types like this: typedef struct { //
I have a DataTable object that contains all the data for a Table visualization.
I have a library that interacts with our phone system, ie, Hey phone, call

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.