search

Home  >  Q&A  >  body text

python - 请教c++项目中,一般是类里的函数具体点好,还是main中具体点好

比如一个函数完成后提示 完成了,这个提示放在main好还是函数里?在看primer plus感觉作者倾向于前者,函数简单,但是main看起来很多

PHP中文网PHP中文网2809 days ago445

reply all(4)I'll reply

  • PHPz

    PHPz2017-04-18 09:50:13

    Define a private logger。在函数执行各个阶段往logger里打日志。在logger with a settergetter method in the class. The configuration specifies the level that needs to be printed to the screen.

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:50:13

    Since we want to prompt the function to complete, the function completion sign is normal return, so it is better to do it in main

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:50:13

    It is better to keep main simple. MFC and the like do not even use main directly, but implement program initialization through the constructor of the global object AppInstance. Specific logic is best encapsulated into classes.

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:50:13

    There is no doubt that it is more appropriate to prompt the status in a specific function. The main function is the entry point of the program, and it is impossible to prompt the status of all functions and classes. For example, if a function calls another function, this nesting cannot be seen in the main function, so how can the status be prompted in the main function.

    reply
    0
  • Cancelreply