⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cplusplus.html

📁 this is a mirrored site c-faq. thought might need offline
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN"><!-- This collection of hypertext pages is Copyright 1995-2005 by Steve Summit. --><!-- Content from the book "C Programming FAQs: Frequently Asked Questions" --><!-- (Addison-Wesley, 1995, ISBN 0-201-84519-9) is made available here by --><!-- permission of the author and the publisher as a service to the community. --><!-- It is intended to complement the use of the published text --><!-- and is protected by international copyright laws. --><!-- The on-line content may be accessed freely for personal use --><!-- but may not be published or retransmitted without explicit permission. --><!-- --><!-- this page built Sat Dec 24 21:47:47 2005 by faqproc version 2.7 --><!-- from source file othlang.sgml dated Wed Dec 21 13:06:13 2005 --><!-- corresponding to FAQ list version 4.0 --><html><!-- Mirrored from c-faq.com/misc/cplusplus.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:59:05 GMT --><head><meta name=GENERATOR content="faqproc"><title>Question 20.27</title><link href="langtran.html" rev=precedes><link href="soundex.html" rel=precedes><link href="index.html" rev=subdocument></head><body bgcolor="#ffffff"><a href="langtran.html" rev=precedes><img src="../images/buttonleft.gif" alt="prev"></a><a href="index.html" rev=subdocument><img src="../images/buttonup.gif" alt="up"></a><a href="soundex.html" rel=precedes><img src="../images/buttonright.gif" alt="next"></a>&nbsp;<a href="../index-2.html"><img src="../images/buttontop.gif" alt="top/contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><hr><p><!-- qbegin --><h1>comp.lang.c FAQ list<font color=blue>&middot;</font><!-- qtag -->Question 20.27</h1><p><font face=Helvetica size=8 color=blue><b>Q:</b></font>Is C++ a superset of C?What are the differences between C and C++?Can I use a C++ compiler to compile C code?</p><p><hr><p><font face=Helvetica size=8 color=blue><b>A:</b></font>C++ was derived from C,and is largely based on it,but there are some legal C constructswhich are not legal C++.Conversely,ANSI C inherited several features from C++,including prototypes and <TT>const</TT>,so neither language is really a subset or superset of the other;the two also define the meaning of some common constructs differently.</p><p>The most important feature of C++ not found in C is of course the extended structureknown as a <TT>class</TT>whichalong with operator overloadingmakes object-oriented programming convenient.There areseveralother differences and new features:variables may be declared anywhere in a block;<TT>const</TT> variablesmay be true compile-timeconstants;structure tags are implicitly typedeffed;an <TT>&amp;</TT> in a parameter declaration requests pass by reference;andthe <TT>new</TT> and <TT>delete</TT> operators,along with per-object constructors and destructors,simplify dynamic data structure management.There area host ofmechanisms tied up with classes and object-oriented programming:inheritance,<TT>friend</TT>s,virtual functions,templates,etc.(This list of C++ features is not intended to be complete;C++ programmers will notice many omissions.)</p><p>Somefeatures of C which keep it from being a strict subset of C++(that is, which keep C programs from necessarily being acceptable to C++ compilers)are that<TT>main</TT>may be called recursively,character constants are of type <TT>int</TT>,prototypes are not required,and<TT>void&nbsp;*</TT>implicitly converts to other pointer types.Also, every keyword in C++ which is not a keyword in Cis available in C as an identifier;C programs which use words like <TT>class</TT> and <TT>friend</TT>as ordinary identifiers will be rejected by C++ compilers.</p><p>In spite of the differences,manyC programs willcompile correctly in a C++ environment,and many recent compilersoffer both C and C++ compilation modes.(But it's usually a bad idea to compile straight C code as if it were C++;the languages are different enoughthat you'll generally get poor results.)</p><p>See alsoquestions <a href="../charstring/sizeofchar.html">8.9</a> and <a href="nestcomment.html">20.20</a>.</p><p>Additional links:<br><br><a href="http://www.research.att.com/~bs/bs_faq.html#C-is-subset">Bjarne Stroustrup's answer</a>on the subset/superset question<br><br>an<a href="cplusplus.rs.html">article by Richard Stamp</a>listing some differences<br><br>an<a href="cplusplus.nr.html">article by ``Noone Really''</a>listing some more</p><p>References:H&amp;S p. xviii, Sec. 1.1.5 p. 6, Sec. 2.8 pp. 36-7, Sec. 4.9 pp. 104-107<br></p><!-- aend --><p><hr><a href="langtran.html" rev=precedes><img src="../images/buttonleft.gif" alt="prev"></a><a href="index.html" rev=subdocument><img src="../images/buttonup.gif" alt="up"></a><a href="soundex.html" rel=precedes><img src="../images/buttonright.gif" alt="next"></a>&nbsp;<a href="../questions.html"><img src="../images/buttontop.gif" alt="contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><br><!-- lastfooter --><a href="../about.html">about this FAQ list</a>&nbsp;<a href="../eskimo.html">about eskimo</a>&nbsp;<a href="../search.html">search</a>&nbsp;<a href="../feedback.html">feedback</a>&nbsp;<a href="copyright.html">copyright</a><p>Hosted by<a href="http://www.eskimo.com/"><img src="../../www.eskimo.com/img/link/eskitiny.gif" alt="Eskimo North"></a></body><!-- Mirrored from c-faq.com/misc/cplusplus.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:59:05 GMT --></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -