c++ - Suppress output from base class constructor -


i have series of classes tells debug stream (std::cout in case) has been created, allowing me follow program execution nicely. have several classes subclasses of base classes not abstract, results in double message when subclass instance created. suppress output in base class constructor when called subclass. know isn't possible without fancy trick, if possible @ all.

i did think of using backspace escape sequence \b, , doing enough of delete previous message not efficient, it's debug info, performance isn't critical then...). i'm not sure of portability or effectiveness of approach.

any ideas welcome, effort!

there's no way suppress code in base constructor, unless code in base constructor checks condition itself. may achieve e.g. passing special flag base constructor (having default value not prohibiting debug output).

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

outputting \b's won't if output redirected file etc.

a decent solution create virtual function returns string, , output result of function. won't work case (calling constructor), during base constructor run virtual functions behave if instance of base type, not derived.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -