C++ for C# Developers

by Mark Williams   Last Updated December 07, 2017 11:05 AM

I know C# pretty well (self-taught, sadly) and need to do some C++ programming for a Windows application. I have been able to find a ton of information for C++ developers learning C# but haven't been able to find much on learning C++ when you already know C#. Has anyone come across a good rundown of the basics?

MSDN has a comparison but it is not very in-depth.

I can piece together several sources but figured something was out there - I just can't find it. Thanks for your help.

Tags : c# c++


Answers 10


Unfortunately, there's not much about C++ that's basic, so I wouldn't get your hopes up. In addition, there's little you'll know about C# that's even remotely transferrable to C++, so I wouldn't expect any specific material to exist covering that angle. You'll need to learn from scratch.

DeadMG
DeadMG
January 02, 2012 18:58 PM

There's no easy fix for this, C++ isn't particularly difficult, but its not easy for beginners.

I would recommend reading up on the basics of C programming (to get a grounding of the low level stuff you'll find), then learn the STL, followed by articles from the likes of Scott Meyers. Here's one to get you started, as it shows how you should be writing modern C++, compared to C-with-classes.

gbjbaanb
gbjbaanb
January 02, 2012 19:27 PM

This thread on C++ for Java developers is very similar and should be useful, especially Mark Byer's post:

Read these books:

Probably the most important thing to keep in mind is to understand the difference in memory management techniques between C#/Java and C++.

One of my profs came from a Java background and taught an introductory C++ course thinking it would be cake. Nothing he explained made any sense to anyone. He had had memory leaks everywhere. His pointer arithmetic was terrible. He never got to the OOP part of the syllabus (thank god). Virtually nothing he demonstrated would have compiled. He didn't understand that char[] needed a sentinel \0. Don't end up like him.

Rei Miyasaka
Rei Miyasaka
January 03, 2012 06:11 AM

Believe me, Pick a good book on C++ (there are much more, just do a search) and start learning...

Muhammad Hewedy
Muhammad Hewedy
January 03, 2012 10:21 AM

I think it is good that you dont find too many C# to C++ tutorials. They may probably muddle up your brain. Its a lot like trying to learn riding a motorcycle first and then switching to a bicycle (not an entirely appropriate anology but you get the idea). It is better for you to take a fresh book on C++. Since you are already familiar with the OOP concepts you can either skip the lengthy introductions to OOP concepts( they are meant for people migrating from C to C++). Or go diretly for a reference book meant for begginer-to-intermediate or intermediate levels.

DPD
DPD
January 03, 2012 11:13 AM

  • Look out for memory management. Get clear idea on how pointers and references work in C++ in contrast to C#. Also, RAII, manual memory management and smart pointers at last.
  • Templates and generics looks similar but are different beasts. Know the internals of how templates work.
  • There are some tiny but catchy syntactic differences. Learn them.
  • You have get used to STL instead of .net BCL. You may going to miss some good bits if have LINQ addiction.
  • There are some fundamental design difference between C++ and C#. So, you cannot just port an idea. Anything you build with C++, you have to design from scratch.
  • Goodluck
Gulshan
Gulshan
January 04, 2012 11:03 AM

I would recommend going to Rosetta Code and comparing the two. While you are there keep handy a link of C++ idioms and try to spot them. Then spend some time on the pointer/reference/memory/destructor realm. After that learn about the preprocessor -- it can really be your friend when it comes to hiding the uglies, I kind of miss it. Finally, the STL.

Mark
Mark
January 15, 2012 03:19 AM

I'm not sure if you're still looking for materials, I found this article a few months ago. It isn't a book (only 53 pages). The introduction says it all:

This is a somewhat short guide to the important things to know if you are a C# programmer and find yourself needing or wanting to work in C++

http://geekswithblogs.net/mikebmcl/archive/2012/02/02/c-to-c-ndash-a-somewhat-short-guide.aspx

And there is also an update post too:

http://geekswithblogs.net/mikebmcl/archive/2012/02/14/c-to-cndasha-somewhat-short-guide-update-1.aspx

Happy learning :)

Chris
Chris
August 17, 2012 22:49 PM

So, about one year ago I was in the same boat as you: self taught c# dev who felt the need to learn C++. Granted, I stopped and started multiple times. On my third attempt, I finally stuck through it.

What is imperative to understand is that, in terms of C++ and C# methodologies, you will likely spend a lot of time understanding what data manipulation methods through pointers and references really means, as well as when and how to use them given the circumstances.

The nice thing about C++ is that object stack allocation is quite simple for the most part, and you should allocate objects this way if your program will meet the requirements specified under this method. Otherwise, you rely on pointers for speed, efficiency, and quick clean up. I recommend reading this: http://www.parashift.com/c++-faq-lite/ as it will give you a LOT of technical understanding of how C++ works under the hood.

Let me give you an example:

In C++ there exists this constructor implementation known as an "initialization list", which differs from initializing class members in the body of a constructor. Why? Because unless the type being initialized is primitive, the compiler will actually create multiple, and unnecessary copies of the object being created when allocated in the ctor's body. This can potentially reduce performance, depending on the compiler as well as the scaled requirements of the app.

Know what a delegate is? Well, in C++ it is known as a function pointer. This language is quite difficult to master at first, but if you want to be awesome... it's definitely required.

C# is easy...very easy.

about blank
about blank
August 18, 2012 11:10 AM

I tried many books, all for absolute beginners, which is too wordy, and also video courses (pluralsight has some good c++ video course). In the end, I found Professional C++ (3rd edition, covers C++ 11 & C++ 14) is a very good one. It is short and to the point with easy to understand examples, the layout, wordings, printings etc are good. C++ primer is recommended by many programmers, but just too dry for me.

Timeless
Timeless
December 07, 2017 10:13 AM

Related Questions