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

后端 未结 4 833
爱一瞬间的悲伤
爱一瞬间的悲伤 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:14

    A common answer might be to provide an "application" singleton class, like e.g. QApplication in Qt, an reduce your main to something like

    int main (int argc, char** argv) {
        YourApplication app (argc, argv);
        return app.execute();
    }
    

    Then you reduce your friendness concern to class YourApplication vs your other classes, and you know how to do that.

提交回复
热议问题