从 Java/C# 到 C++ 的最佳方式是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-01 09:02:28  来源:igfitidea点击:

What is the best way to go from Java/C# to C++?

提问by Bryan Denny

At my university most of my classes have been in Java. I have also recently learned C# (and the Visual Studio environment) at a summer internship. Now I'm taking an Intro to Computer Graphics class and the grad student teaching the class prefers us to use C++ to access the OpenGL bindings via GLUT.

在我的大学里,我的大部分课程都是 Java 课程。我最近还在暑期实习中学习了 C#(和 Visual Studio 环境)。现在我正在学习计算机图形学入门课程,教授该课程的研究生更喜欢我们使用 C++ 通过 GLUT 访问 OpenGL 绑定。

Does anyone have any good resources on how to make a good transition from Java/C# to C++? Obviously pointers are going to be a big issue, but any other things I should be looking out for? Any tutorials, guides, etc. would be very helpful!

有没有人有关于如何从 Java/C# 到 C++ 的良好过渡的任何好的资源?显然,指针将是一个大问题,但是我应该注意其他任何事情吗?任何教程、指南等都会非常有帮助!

Thanks!

谢谢!

采纳答案by David McGraw

Yeah, I got bit by the same bug. The university tended to lean on Java, and then allowed you to choose the language you wanted to work with during projects.

是的,我被同样的错误咬了。这所大学倾向于使用 Java,然后允许您在项目期间选择要使用的语言。

The best way is to just jump in. Start small, take baby steps, and just Google things that confuse you when you get there. Also find projects that have released their source code. See how they structure their programs. Basically, just tinker with concepts. There is plenty of information around the web.

最好的方法是直接加入。从小处着手,采取婴儿的步骤,然后在谷歌上搜索那些当你到达那里时让你感到困惑的东西。还可以找到已发布其源代码的项目。看看他们如何构建他们的程序。基本上,只是修补概念。网络上有很多信息。

Make it fun and grab a C++ game development bookso it doesn't become mind numbing too quickly.

让它变得有趣并拿一本C++ 游戏开发书,这样它就不会太快变得头脑麻木。

Here's some places that I found useful while learning

以下是我在学习过程中发现有用的一些地方

http://www.cprogramming.com/

http://www.cprogramming.com/

http://www.wikipedia.com

http://www.wikipedia.com

http://www.cplusplus.com/

http://www.cplusplus.com/

回答by Kyle Cronin

If you already know Java/C# I'd recommend going directly to C instead of C++. According to the website, GLUT has the same bindings for C as C++ so you should be all set. Anyways, the best way to learn C is to purchase and read a copy of "The C Programming Language" and sit down with your C compiler and get your stuff to run.

如果您已经了解 Java/C#,我建议您直接使用 C 而不是 C++。根据该网站,GLUT 具有与 C++ 相同的 C 绑定,因此您应该已准备就绪。无论如何,学习 C 的最佳方法是购买并阅读“C 编程语言”的副本,然后与您的 C 编译器坐下来,让您的东西运行起来。

回答by ftdysa

Effective C++ by Scott Meyers is a great book to help you learn C++. Gives you an overview of the language and introduces a lot of key concepts that you will use throughout the development of basically any C++ program.

Scott Meyers 的 Effective C++ 是一本帮助您学习 C++ 的好书。为您提供该语言的概述,并介绍了您将在基本上任何 C++ 程序的整个开发过程中使用的许多关键概念。

回答by Dan Blair

Effective C++ by Scott Meyers is a great book to help you learn C++. Gives you an overview of the language and introduces a lot of key concepts that you will use throughout the development of basically any C++ program.

Scott Meyers 的 Effective C++ 是一本帮助您学习 C++ 的好书。为您提供该语言的概述,并介绍了您将在基本上任何 C++ 程序的整个开发过程中使用的许多关键概念。

I love this book in all 3 editions, and it was one of the books in a class I had as a Senior at UT, but it's just not a starting book. You can become comfortable in C++ with a lot less, though you certainly won't be one with the compiler until you have read Meyer's work.

我喜欢这本书的所有 3 个版本,它是我在 UT 大四时上过的班级中的一本书,但它不是入门书。你可以用更少的东西来适应 C++,尽管在你阅读 Meyer 的作品之前你肯定不会成为编译器的一员。

I don't know if it's still in print but I found Navigating C++usefull, but I was also very comfortable with pointers from Pascal. Err of course I am forgetting that 15 years ago you had to learn what OOP was, now it's a little more assumed. So perhaps Meyer's is not out of line. Thoughts?

我不知道它是否仍在印刷中,但我发现Navigating C++很有用,但我对 Pascal 的指针也很满意。呃,当然我忘记了 15 年前你必须了解 OOP 是什么,现在它更假设了一点。所以也许迈耶的不是出格的。想法?

回答by Mark Cidade

Wikipedia has an article on comparisons between Java and C++.

维基百科有一篇关于Java 和 C++ 之间比较的文章。

You don't have to worry about checked exceptions in C++, but you do need to know about const correctness.

您不必担心 C++ 中的检查异常,但您确实需要了解const 正确性

回答by postfuturist

There are two main differences: the syntax, and memory management.

有两个主要区别:语法和内存管理。

In C++ you have pointers, which are more powerful (or less powerful depending on your interpretation of power) object references, which you already know about from Java.

在 C++ 中,你有指针,它们更强大(或者更弱,取决于你对权力的解释)对象引用,你已经从 Java 中知道了。

In Java you might do this:

在 Java 中,你可以这样做:

Thing mything = new Thing(); // mything is an object reference
mything.method();

In C++ you would do this:

在 C++ 中,你会这样做:

Thing * mything = new Thing(); // mything is an object pointer
mything->method();
delete mything;

The syntactical difference is obvious: '->' instead of '.' when calling an object method from a pointer to an object. In C++, you have to free the memory explicitly when you are done with an object. At the end of the day you are doing the same thing in C++ and Java, instantiating objects and calling methods, putting useless semicolons at the end of every line, etc. Is it any wonder that Python is becoming so popular?:

语法上的差异很明显:'->' 而不是 '.' 当从指向对象的指针调用对象方法时。在 C++ 中,当你处理完一个对象时,你必须明确地释放内存。归根结底,你在 C++ 和 Java 中做同样的事情,实例化对象和调用方法,在每一行的末尾放置无用的分号等等。 Python 变得如此流行有什么奇怪的吗?:

mything = Thing() # mything is whatever I want it to be
mything.method()

Skimming through any half decent C++ text will help you fill in the rest of the details.

浏览任何半体面的 C++ 文本将帮助您填写其余的细节。

回答by Cheekysoft

I also thoroughly recommend Bruce Eckel's Thinking in C++. A fantastic book for already experienced programmers that want to get into the C++ mindset.

我还彻底推荐 Bruce Eckel's Thinking in C++。对于想要进入 C++ 思维模式的已经有经验的程序员来说,这是一本很棒的书。

He is kind enough to make electronic versions of his books available for free.

他很友好地免费提供他的书的电子版。

回答by Kristopher Johnson

I strongly recommend that anyone learning C++ reads Stroustrups "The C++ Programming Language." Meyers and Eckel have great stuff, but nothing beats learning from the guy who decided what the language should be and how he intended for it to be used.

我强烈建议任何学习 C++ 的人都阅读 Stroustrups “The C++ Programming Language”。Meyers 和 Eckel 有很棒的东西,但没有什么比向决定语言应该是什么以及他打算如何使用它的人学习更好的了。

回答by adeel825

I had the exact same issue. The only book I was able to find was "Pro Visual C++ 2005 for C# Developers" by Dean C. Wills. It's a good read with excellent examples, and I think the angle from which the book comes is probably what you're looking for.

我有完全相同的问题。我能找到的唯一一本书是Dean C. Wills 的“Pro Visual C++ 2005 for C# Developers”。这是一本很好的书,有很好的例子,我认为这本书的角度可能就是你正在寻找的。

回答by Franz Kafka

You will need a completely differnt feeling for memory handling. Also think about freeing everything you don't need anymore. In Java and C# you just let go of your objects and the memory gets tidy up for you - you can't do that in CPP

您将需要一种完全不同的内存处理感觉。还要考虑释放您不再需要的一切。在 Java 和 C# 中,您只需放开对象,内存就会为您整理好 - 在 CPP 中无法做到这一点