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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:09:26+00:00 2026-05-18T09:09:26+00:00

I have a series of classes that tells the debug stream ( std::cout in

  • 0

I have a series of classes that tells the debug stream (std::cout in this case) that it has been created, allowing me to follow the program execution nicely. I have several classes that are subclasses of base classes which are not abstract, which results in a double message when a subclass instance is created. I would like to suppress the output in the base class constructor when it is called from a subclass. I know this probably isn’t possible without some fancy trick, if it is even possible at all.

I did think of using the backspace escape sequence \b, and doing just enough of that to delete the previous message not really efficient, but it’s debug info, performance isn’t that critical then…). I’m not sure of the portability or effectiveness of this approach.

Any ideas are welcome, thanks for the effort!

  • 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-18T09:09:27+00:00Added an answer on May 18, 2026 at 9:09 am

    There’s no way to suppress the code in the base constructor, unless the code in the base constructor checks some condition itself. You may achieve this by e.g. passing a special flag to the base constructor (having default value NOT prohibiting the debug output).

    class Base
    {
      public:
        Base(bool suppressDebugInfo = false)
        {
            if (!suppressDebugInfo)
                cout << "hallo from base" << endl;
        }
    };
    
    class Derived : public Base
    {
      public:
        Derived(bool suppressDebugInfo = false) : Base(true)
        {
            if (!suppressDebugInfo)
                cout << "hallo from derived" << endl;
        }
    };
    

    Outputting \b‘s won’t help if your output is redirected to a file etc.

    A decent solution could be to create a virtual function which returns a string, and output the result of that function. This won’t however work for your case (calling from constructor), as during the base constructor run the virtual functions behave as if the instance is of the base type, not derived.

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

Sidebar

Related Questions

I have a constructor that has a series of classes and functions within it
I have been trying for some time to create a class/series of classes that,
So here is the scenario: i have a series of different repository classes that
I have a series of classes, which are unrelated. Each classs has one property
I want to resolve in Windsor a series of classes that implement this interface:
I have a series of classes that implement a Title (or Name) depending upon
I have a series of classes that I'll be registering as services to a
I have a series of classes that are going to require many boolean fields,
I have a series of if statements in a function like this: if time
I have a series of... pseudo-xml files. What I mean by this, is they

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.