Dan*_*oof 15 c++ oop program-entry-point
这可能是一个简短而简单的问题,但我从来没有找到一个令人满意的答案:
main()函数通常在大型C++项目中包含哪些代码?认为它通常只是初始化一个(包装)类对象并在其中调用一个函数来设置它是不正确的假设?
为什么main()不是第一个方法?它是否保持与C的向后兼容性?
小智 10
在我的代码中,它基本上是构造函数调用,可能是方法调用,以及一些异常处理.这是我自己的项目的主要内容(标题和注释省略,并且格式化由SO乱码,像往常一样):
int main( int argc, char * argv[] ) {
int result = 0;
try {
CLIHandler ch( argc, argv );
result = ch.ExecCommand();
}
catch( const Exception & ex ) {
result = ExceptionHandler::HandleMyError( ex );
}
catch( const std::exception & ex ) {
result = ExceptionHandler::HandleOtherError( ex );
}
catch( ... ) {
result = ExceptionHandler::HandleUnknownError();
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3477 次 |
| 最近记录: |