admin 发表于 2016-9-28 09:20:12

用一年时间如何能掌握 C++ ?

<span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">本人大约从20多年前开始学习及使用C++,但仍未达到我认为「精通」的阶段,甚至对于C++11的各种新特性也未掌握。然而因为我是在读书时自学C++的,也是游戏程序员(原问题中提到题主想从事游戏开发),觉得也许能提供一点意见供网友参考。</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">首先引一下2010年8月号《程序员》刊登的拙文《</span><a href="https://link.zhihu.com/?target=http%3A//www.cnblogs.com/miloyip/archive/2010/09/17/behind_cplusplus.html" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">C++强大背后<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">》最后一段:</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><blockquote style="margin-top: 0.8em; margin-bottom: 0.8em; padding-left: 10px; font-size: 13px; line-height: 22px; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(208, 229, 242); color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><b>C++学习建议</b><p>C++缺点之一,是相对许多语言复杂,而且难学难精。许多人说学习C语言只需一本K&amp;R<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1139336/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C程序设计语言》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>即可,但C++书籍却是多不胜数。我是从C进入C++,皆是靠阅读自学。在此分享一点学习心得。个人认为,学习C++可分为4个层次:</p><ul style="margin-top: 0.8em; margin-bottom: 0.8em;"><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">第一层次,C++基础:挑选一本入门书籍,如<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/4262575/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++ Primer》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>、<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/2030264/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++大学教程》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>、或Stroustrup撰写的经典<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1099889/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++程序设计语言》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>或他一年半前的新作<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/4875599/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++程序设计原理与实践》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>,而一般C++课程也止于此,另外<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1110941/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++ 标准程序库》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>及<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1868179/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《The C++ Standard Library Extensions》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>可供参考;</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">第二层次,正确高效地使用C++:此层次开始必须自修,阅读过《(<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1241385/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">More<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>)<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1842426/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">Effective C++<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>》、《(<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1244943/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">More<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>)<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1967356/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">Exceptional C++<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>》、<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1792179/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《Effective STL》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>及<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1480481/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++编程规范》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>等,才适宜踏入专业C++开发之路;</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">第三层次,深入了解C++:关于全局问题可读<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1091086/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《深入探索C++对象模型》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>、<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1470838/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《Imperfect C++》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>、<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/2970056/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++沉思录》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>、<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1110934/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《STL源码剖析》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>,要挑战智商,可看关于模版及模版元编程的书籍如<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/2378124/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++ Templates》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>、<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1119904/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++设计新思维》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>、<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/4136223/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++模版元编程》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>;</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">第四层次,研究C++:阅读<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/1096216/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《C++语言的设计和演化》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>、<a href="https://link.zhihu.com/?target=http%3A//book.douban.com/subject/4722718/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《编程的本质》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>(含STL设计背后的数学根基)、C++标准文件<a href="https://link.zhihu.com/?target=http%3A//openassist.googlecode.com/files/C%252B%252B%2520Standard%2520-%2520ANSI%2520ISO%2520IEC%252014882%25202003.pdf" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">《ISO/IEC 14882:2003》<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>、<a href="https://link.zhihu.com/?target=http%3A//www.open-std.org/JTC1/SC22/WG21/" class=" wrap external" target="_blank" rel="nofollow noreferrer" style="text-decoration: none; color: rgb(34, 85, 153); -webkit-tap-highlight-color: rgba(225, 225, 225, 0.498039); margin-right: 4px; word-break: break-all;">C++标准委员会<i class="icon-external" style="width: 7px; height: 7px; display: inline-block; vertical-align: 0px; margin-left: 4px; background-image: url(&quot;/static/revved/img/sprites-1.9.2.4c54885a.png&quot;); background-position: 0px -204px; background-repeat: no-repeat;"></i></a>的提案书和报告书、关于C++的学术文献。</li></ul><p>由于我主要是应用C++,大约只停留于第二、三个层次。然而,C++只是软件开发的一环而已,单凭语言并不能应付业务和工程上的问题。建议读者不要强求几年内“彻底学会C++的知识”,到达第二层左右便从工作实战中汲取经验,有兴趣才慢慢继续学习更高层次的知识。虽然学习C++有难度,但也是相当有趣且有满足感的。</p></blockquote><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">如果题主认为的「精通」是指上述所指的第二层次,那么我估计一年全职时间也未足够「精通」。首先,阅读这些书籍本身也需要不少时间,而且对于一般人来说(指除了一些学习记忆能力超强的人),很可能需要阅读几遍才能记住一些细节。另外,阅读后必须要练习。除了入门的习题外,还需要做一些工程向的项目,才能了解各种语法、编程范式的使用方法及时机,理想地建议参与一些开源项目。然而,学习是需要不断思考并把结果沉淀,方法包括与朋友讨论、写博客、写知乎答案等,这些都需要时间。</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">如引文末段所指出,我建议不要把「精通C++」作为一个一年目标,应该要把学习语言作为一个持续的过程,同时要把语言运用在具体的应用场合中。</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">---------------------------------------------------</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">再讨论C++与游戏开发。</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">看到有不少答案讨论到有关C++是否游戏开发者所必须的技术。我认为,这并不是完全必须的,但许多游戏开发项目需要到C++。以下列举一些过往曾流行的游戏平台/类型:</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><ol style="margin-top: 0.8em; margin-bottom: 0.8em; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">PC单机游戏(Windows)</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">PC网络游戏(Windows、Linux)</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">移动平台游戏(J2ME、Symbian、Palm……)</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">家用游戏机游戏(PS1/2/3/4、XBox、Wii……)</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">掌上游戏机游戏(GB、GBA、NDS、PSP……)</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">网页游戏(HTML、Flash)</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">智能移动设备游戏(iOS、Android)</li></ol><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">我们会发现,除了J2ME和网页游戏外,大多数的平台都支持(或只支持)原生编程。而原生编程最常用的就是C/C++和汇编。这种现象并不难解译,再次引用拙文:</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><blockquote style="margin-top: 0.8em; margin-bottom: 0.8em; padding-left: 10px; font-size: 13px; line-height: 22px; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(208, 229, 242); color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><b>应否选择C++<br>哪些程序适宜使用C++?<br></b><br><p>C++并非万能丹,我按经验举出一些C++的适用时机。</p><ul style="margin-top: 0.8em; margin-bottom: 0.8em;"><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">C++适合构造程序中需求较稳定的部分,需求变化较大的部分可使用脚本语言;</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">程序须尽量发挥硬件的最高性能,且性能瓶颈在于CPU和内存;</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">程序须频繁地与操作系统或硬件沟通;</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">程序必须使用C++框架/库,如大部分游戏引擎(如Unreal/Source)及中间件(如Havok/FMOD),虽然有些C++库提供其他语言的绑定,但通常原生的API性能最好、最新;</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">项目中某个目标平台只提供C++编译器的支持。</li></ul><p>按应用领域来说,C++适用于开发服务器软件、桌面应用、游戏、实时系统、高性能计算、嵌入式系统等。</p></blockquote><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">很大程度上,游戏──或说游戏引擎,都是C++非常适合的应用时机。</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">一些人认为,游戏开发者使用现成的引擎,就不需要使用C++了。过往,业界有一个普遍常识,就是用C++开发游戏引擎,而游戏引擎提供脚本引擎供编写游戏逻辑代码。但这个观点被Unreal Engine 4的决策改变,UE4放弃了维护多年且被大量使用的UnrealScript脚本语言,而改用原生C++作为游戏逻辑编程的语言。此决策背后有多个原因,但这里只想举出这例子展示C++在游戏开发中的用途及潮流,具体原因分析就不详细展开了。</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">除了自行研发游戏引擎需要使用C++,我们可以看到,大部分游戏引擎都提供了其C++原代码(Unity算是例外),这让我们可以</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><ol style="margin-top: 0.8em; margin-bottom: 0.8em; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">方便调试游戏</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">深度剖析、优化游戏的性能</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">为引擎扩展新功能</li><li style="margin-bottom: 5px; margin-left: 0px; list-style-position: inside;">修改现有引擎以适应项目所需</li></ol><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">在专业的游戏开发中,这些都是很常见的工作任务。所以,即使并非自研引擎,并使用脚本语言开发游戏逻辑,也有很多机会需要使用C++。</span><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><br style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;"><span style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.1px;">最后,「还需学习什么」是一个很难简单回答的问题,因为游戏开发涉及的知识面很广。建议可参考本人译作。</span><p></p>
页: [1]
查看完整版本: 用一年时间如何能掌握 C++ ?