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 6356537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:58:59+00:00 2026-05-24T22:58:59+00:00

I have a class that inherits from ostream but the manipulators fail to compile.

  • 0

I have a class that inherits from ostream but the manipulators fail to compile. For instance:

QLogger &logger = QLogger::getInstance();

logger << hex << 10 << endl;

Complains about logger << hex. If I cast logger to an ostream it will work but that is pretty ham-handed.

How can I extend my class so that it behaves as an ostream with manipulators?

Thanks,

Kenny

class LIBEXPORT QLogger: public std::ostream
{
    friend class boost::thread_specific_ptr< QLogger >;

    friend class QLoggerFunnel;

public:

    // Priority for message filtering.
    //
    // DEBUG   Detailed information that may be useful during development or troubleshooting.
    // NORMAL  Message will be useful during normal operation.
    // WARNING Message indicates an unhealthy condition but the system should continue to operate.
    // FAULT   Message indicates a critical error. The system may not operate normally.
    enum Priority
    {
        DEBUG, NORMAL, WARNING, FAULT
    };

    // DEPRECATED: Defined for backward compatibility.
    static const Priority LOW = NORMAL;

    static const Priority HIGH = WARNING;

    static const Priority URGENT = FAULT;

    // Returns a reference to the global instance.
    static QLogger& getInstance();

    // DEPRECATED: Use instead: QLogger::instance() << "Example message." << std::endl
    static AWI_DEPRECATED QLogger& stream( QLogger::Priority priority = NORMAL );

    QLogger &operator<<( Priority p );

    // Messages with a priority below the threshold are discarded.
    void setThreshold( Priority priority );

    Priority getThreshold( void ) const;

    // Set the priority of messages.
    void setPriority( Priority priority );

    Priority getPriority( void ) const;

protected:

    static void handleThreadExit( QLogger *logger );

    QLogger();

    QLogger( const QLogger& );

    virtual ~QLogger();

    QLogger& operator=( const QLogger& );

    void write( std::ostream &destination );

    void synchronize( void );

    // Prepends information to each line of its associated output stream.
    class StampBuffer: public std::stringbuf
    {
        public:

            StampBuffer();

            virtual ~StampBuffer();

            // String to be displayed before each line.
            void setPreamble( const char *p );

            virtual int sync();

            void write( std::ostream &destination );

        protected:

            boost::mutex _mutex;

            std::stringstream _stream1;

            std::stringstream _stream2;

            // Active stream being written to.
            std::stringstream *_write;

            std::stringstream *_read;

            const char *_preamble;
    };

    class NullBuffer: public std::stringbuf
    {
        public:

            NullBuffer();

            virtual ~NullBuffer();

            virtual int overflow( int c )
            {
                return (c);
            }
    };

    StampBuffer _buffer;

    NullBuffer _null_buffer;

    Priority _threshold;

    Priority _priority;
};
  • 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-24T22:59:00+00:00Added an answer on May 24, 2026 at 10:59 pm

    If you implement a member function, then inherited overloads of that same function aren’t considered in overload resolution. If you change your custom operator<< overloads to be friend global functions rather than members, this should work fine. The cast forces the compile to choose operator<<() from those defined in ostream.

    The special overload for the function pointer isn’t needed.

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

Sidebar

Related Questions

Example: I have an class that inherits from UIImageView. An object creates an instance
I have a class (Descendant1) that inherits from a base class (BaseClass). An instance
I have a class that inherits from ObservableCollection<T> to re-use the INotifyCollection functionality, but
I have a class that inherits from Dictionary<string, string> . Within an instance method,
I have a class that inherits from ObservableCollection(Of MyObject) and the MyObject class handles
I have a class that inherits from a base class (this contains a lot
I have a class that inherits from a generic dictionary as follows: Class myClass
I have a class that inherits from Page, called APage. public abstract class APage:
If we have a class that inherits from multiple interfaces, and the interfaces have
I have a class A and another class that inherits from it, B. I

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.