为什么没有main定义`main(std :: vector< std :: string> args)`? [英] Why isn't main defined `main(std::vector<std::string> args)`?

查看:119
本文介绍了为什么没有main定义`main(std :: vector< std :: string> args)`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题只是一半的舌头。我有时梦想一个没有裸体数组或c字符串的世界。

This question is only half tongue-in-cheek. I sometimes dream of a world without naked arrays or c strings.

如果你使用的是c ++,那么main的首选定义不应该是:

If you're using c++, shouldn't the preferred definition of main be something like:

int main(std::vector<std::string> args)

main 已有多个定义可供选择,为什么没有是C ++的精神吗?

There are already multiple definitions of main to choose from, why isn't there a version that is in the spirit of C++?

推荐答案

不断回到我的想法是,一旦你允许复杂类型,你结果是在类型的构造函数中抛出异常的风险。并且,因为语言是目前设计的,绝对没有办法抓住这样的异常。如果决定应该捕获这些异常,那么对于委员会和编译器作者来说,这将需要大量更多的工作,使得它比仅仅说allow std :: vector< std :: string>>

A concern that keeps coming back to my mind is that once you allow complex types, you end up with the risk of exceptions being thrown in the type's constructor. And, as the language is currently designed, there's absolutely no way for such an exception to be caught. If it were decided that such exceptions should be caught, then that would require considerably more work, both for the committee and compiler writers, making it all somewhat more troublesome than simply saying "allow std::vector<std::string>>".

可能还有其他问题。整个与运行时不兼容似乎是一个红色的鲱鱼给我,因为你可以提供基本相同的功能现在与宏。但是像这样的事情更相关。

There might be other issues as well. The whole "incompatible with runtimes" seems like something of a red herring to me, given that you can provide basically the same functionality now with macros. But something like this is rather more involved.

这篇关于为什么没有main定义`main(std :: vector&lt; std :: string&gt; args)`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆