custom stream manipulator for class

前端 未结 4 1368
情话喂你
情话喂你 2020-12-20 10:44

I am trying to write a simple audit class that takes input via operator << and writes the audit after receiving a custom manipulator like this:

class C         


        
4条回答
  •  执笔经年
    2020-12-20 11:07

    To make it work you have to add overload of operator << for functions, than call the function from it:

     class CAudit
     {
      //...other details here as in original question
    
      CAudit& operator << (CAudit & (*func)(CAudit &))
      {
            return func(*this);
      }
     };
    
     CAudit audit;
     audit << "some text" << CAudit::write;
    

提交回复
热议问题