How does QDebug() << stuff; add a newline automatically?

前端 未结 4 1659
挽巷
挽巷 2020-12-30 05:11

I\'m trying to implement my own qDebug() style debug-output stream, this is basically what I have so far:

struct debug
{
#if defined(DEBUG)
             


        
4条回答
  •  旧巷少年郎
    2020-12-30 05:56

    The stream insertion (<<) and extraction (>>) are supposed to be non-members.

    My question is basically, how can I tell when the return type of operator<< isn't going to be used by another operator<< (and so append endl)?

    You cannot. Create a member function to specially append this or append an endl once those chained calls are done with. Document your class well so that the clients know how to use it. That's your best bet.

提交回复
热议问题