简体   繁体   English

C++ 来自 Java 和 Objective-C

[英]C++ coming from Java and Objective-C

So, I know both Java and Objective-C quite well, but (perhaps strangely) never really learned C++.所以,我对 Java 和 Objective-C 都非常了解,但(也许很奇怪)从未真正了解过 C++。 Obviously, the languages are all related, but there are syntactical differences that I don't fully understand.显然,这些语言都是相关的,但存在我不完全理解的语法差异。 Is there a nice document that describes the basics of C++, but still assumes the learner knows a programming language?是否有一个很好的文档来描述 C++ 的基础知识,但仍然假设学习者知道一门编程语言? Perhaps even a tutorial that aims to describe the differences between the languages.也许甚至是旨在描述语言之间差异的教程。 This is what I'm looking for.这就是我要找的。

Also, is there a good tutorial on how to use C++ code inside a Mac or iOS app?此外,是否有关于如何在 Mac 或 iOS 应用程序中使用 C++ 代码的好教程? The reason I feel the need to learn C++ is I'm trying to port a C++ program, and I heard you can use C++ code and just wrap it in an Obj-C GUI.我觉得需要学习 C++ 的原因是我正在尝试移植 C++ 程序,我听说你可以使用 C++ 代码并将其包装在 Obj-C GUI 中。 Could someone point me to some documentation/tutorials on how to do this?有人可以向我指出一些有关如何执行此操作的文档/教程吗?

Thanks!谢谢!

Even though the languages of this family are all related, that does not mean that you can casually move from one to the other and expect to write beautiful code.尽管这个家族的语言都是相关的,但这并不意味着你可以随便从一种语言迁移到另一种语言并期望编写漂亮的代码。 You have to learn the language's idioms and idiosyncrasies, and experience its strengths and way of thinking.您必须学习该语言的习语和特质,并体验其优势和思维方式。

I would recommend reading Stroustrup's original book (a modern edition, of course).我建议阅读 Stroustrup 的原著(当然是现代版)。 It's the most definitive reference (short of the actual standard) and it is very clearly written.这是最权威的参考资料(没有实际标准),而且写得很清楚。 The benefit of this approach is that you will be taught to think "how would I do this in C++", rather than "how do I transliterate this piece of Java code to make it compile".这种方法的好处是您将被教导思考“我将如何在 C++ 中执行此操作”,而不是“我如何音译这段 Java 代码以使其编译”。 (Also this approach does away with any risk you might have of thinking you should "learn C first" . Don't.) (此外,这种方法消除了您可能认为应该“首先学习 C”的任何风险。不要。)

On MacOSX, either download and build the free GCC, or get XCode (which comes with GCC).在 MacOSX 上,要么下载并构建免费的 GCC,要么获取 XCode(GCC 随附)。 For iOS I don't know, I have a suspicion that you cannot deploy native code on it.对于 iOS 我不知道,我怀疑您无法在其上部署本机代码。

I would go for a pure C++ route, the quality of the material being the guide rather than finding ObjC+Java->C++ material.我将 go 用于纯 C++ 路线,材料的质量是指导而不是寻找 ObjC+Java->C++ 材料。

At the university I am working for we have tried both ways for teaching C++ to students with a lot of programming experience, in particular Java experience, for obvious reasons.在我工作的大学里,出于显而易见的原因,我们尝试了两种方法来向具有丰富编程经验的学生教授 C++,特别是 Java 经验。

The conclusion was that the specialized course did no better in teaching C++ than the generic one with some extra exercise materials.结论是,专业课在教授 C++ 方面的效果并不比普通课和一些额外的练习材料好。 It's the quality of the teaching materials that matters.重要的是教材的质量。

Edit: You will probably receive a lot of good answers on the actual differences, also Voo's comment on your question is relevant.编辑:您可能会收到很多关于实际差异的好答案,Voo 对您的问题的评论也是相关的。

I know what you feel - to have already worked on a couple of languages and learning C++.我知道你的感受——已经使用过几种语言并学习过 C++。 I was in the same boat too.我也在同一条船上。 While I was thinking for a while that it should be easy for me to learn it right away, it wasn't all that easy.虽然我想了一会儿,我应该很容易马上学会它,但这并不是那么容易。 So then I went back to the basics and started as a fresher to learn C++.所以我回到基础,开始学习 C++。 'C++ Primer' is an extremely good book to start with. 《C++ Primer》是一本非常好的入门书籍。 Since you know most of the basics of programming, some of the first few chapters can be skimmed through.由于您了解编程的大部分基础知识,因此可以略读前几章中的一些内容。 Once you are through with this, I'd recommend 'Effective C++' book and the C++ FAQs maintained here [http://www.parashift.com/c++-faq-lite/].一旦你完成了这个,我会推荐“Effective C++”一书和 C++ 常见问题解答 [http://www.parashift.com/c++-faq-lite/]。

In fact, you could go through this FAQ first and see how much of it makes sense, and use that as a guide for figuring out where to do a deep dive.实际上,您可以先通过此常见问题解答 go 看看其中有多少意义,并将其用作确定在哪里进行深入研究的指南。

HTH, K HTH, K

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM