How do I make main a friend of my class from within a library?

后端 未结 4 823
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-12 03:03

Please see my first attempt at answering this . I neglected to tell the whole story before in an attempt to simplify things. Turns out my example works! Sorry.

The w

4条回答
  •  春和景丽
    2021-01-12 03:13

    Just declare the main outside the MyNamespace and specify global namespace :: in friend statement

    //in header file of ProcessManager
    //your pf.h
    
    int main(int argc, char** argv);
    
    namespace MyNamespace
    {
      class ProcessManager
      {
      public:
        friend int ::main(int argc, char** argv);
      private:
        void test();
      };
    };
    

提交回复
热议问题