C和C ++之间的主要区别是什么,什么时候选择一个? [英] What are the major differences between C and C++ and when would you choose one over the other?

查看:146
本文介绍了C和C ++之间的主要区别是什么,什么时候选择一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于那些对两者都有经验的人,主要的区别是什么?对于新来的人,哪个会更好地学习?有没有情况下,你可能选择C,但其他情况下,你会选择C ++?是使用最好的工具的情况下,或者一个明显比另一个更好。我知道C ++是C的增强,但它是在'83创建的,并没有完全取代C,所以必须有一些更多的东西。

For those of you with experience with both, what are the major differences? For a newcomer to either, which would be better to learn? Are there situations where you might choose C but then other situations where you would choose C++? Is it a case of use the best tool for the job or one is significantly better than the other. I know C++ is an "enhancement" of C, but it was created in '83 and hasn't completely replaced C so there must be something more to it.

I知道这个问题是主观的,我不是想开始任何宗教战争,所以请尽量做到尽可能客观。清楚的优点和弱点和比较。

I know this question is subjective and I am not trying to start any religious war, so please try to be as objective as possible. Clear strengths and weaknesses and comparisons.

推荐答案

虽然C是一个纯程序语言,C ++是一个多范式语言。它支持

While C is a pure procedural language, C++ is a multi-paradigm language. It supports


  • 通用编程:允许编写一次代码,并将其用于不同的数据结构。

  • 元编程:允许在编译时使用模板生成高效的代码。

  • 检查:允许在编译时检查某些属性:表达式有什么类型?一个函数有多少个参数?

  • 面向对象编程:允许程序员编程面向对象,具有复杂的特性,如多继承和私有继承。

  • 程序编程:允许程序员将函数放入任何类。结合高级功能,如ADL允许编写干净的代码从某些类的细节解耦。

  • Generic programming: Allowing to write code once, and use it with different data-structures.
  • Meta programming: Allowing to utilize templates to generate efficient code at compile time.
  • Inspection: Allows to inspect certain properties at compile time: What type does an expression have? How many parameters does a function have? What type does each one have?
  • Object oriented programming: Allowing the programmer to program object oriented, with sophisticated features such as multiple inheritance and private inheritance.
  • Procedural programming: Allows the programmer to put functions free of any classes. Combined with advanced features such as ADL allows writing clean code decoupled from specifics of certain classes.

除此之外,C ++在很大程度上保持与C代码的兼容性,但有一些差异。这些可以在C ++标准的附录D中阅读,连同原因并且可能固定为使C代码成为有效的C ++代码。

Apart from those, C++ has largely kept compatibility with C code, but there are some differences. Those can be read about in Annex D of the C++ Standard, together with reasons and possible fixed to make C code valid C++ code.

这篇关于C和C ++之间的主要区别是什么,什么时候选择一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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