How should a .NET developer learn C ++?

Ok The following is a brief overview of my experience / knowledge / etc:

  • I worked with only two languages: C # and F #
  • I only know programming in a controlled environment
  • I have a strong understanding of C # syntax
  • I have a clear understanding of the C # type system.
  • I never looked at a line of code in C ++
  • I do not know systems like C ++.

I am concerned that the C ++ community / books / resources / etc will use similar words used in C # community / books / resources / etc, but meaning slightly different (or completely different) things. This concern may not be valid, but to stick to one question, I will simply ask; How should a .NET developer learn C ++?

Note. I am learning C ++ for interoperability purposes.

+7
c ++ interop
source share
7 answers

If you are doing this for interaction, there are two things to keep in mind.

  • You do not need to learn all of C ++. Keep it simple. You most likely need to know enough to call APIs intended for use with C. Thus, you will mainly use a C-like subset of C ++, but with the added convenience of using standard C ++ container types for dynamic allocation ( for example, to highlight the vector of structures). In C ++, the ability to use a template container is far from being able to develop it yourself, and, fortunately, you will need to use them.

  • The most powerful and flexible way to publish C ++ - developed code for .NET clients is to use C ++ / CLI, so you need to get the basics of it; in particular, an understanding of how to make the C # equivalent in C ++ / CLI. This may be misleading.

Given the type of .NET C that IDisposable supports, this C ++:

 C c; c.Foo(); 

equivalent to this C #:

 using (C c = new C()) c.Foo(); 

While this C #:

 C c = new C(); c.Foo(); c.Dispose(); 

will be equivalent to this C ++ / CLI:

 C ^c = gcnew C; c->Foo(); delete c; 

So stop reading. All this on MSDN .

+2
source share

You must find an application to write in it, which is the best way to find out.

+6
source share

Just grab a book in C ++ or use an equivalent online resource. At the moment, I can not imagine a single aspect of C # that means something completely different in C ++. Here are some of the main differences that you might want to consider more closely (from the head):

  • C ++ allows multiple inheritance
  • C ++ preprocessor directives are very efficient (and confusing at the same time)
  • Pointers

[edit] Forgot to mention another very important difference: in C ++ there is no default garbage collection. You either have to manage your dynamic memory manually, or enable garbage collection. Here is one implementation of the garbage collection in C ++.

+2
source share

At first I learned C, if I just "untied" all the additional C #.

then C ++ would be easy if you donโ€™t remember not to display concepts

+1
source share

I would recommend starting with Koenig and Moo Accelerated C ++ - perhaps the only C ++ introduction that doesn't get into C-c -knobs-on trap.

+1
source share

We all learn best in our own way. In your question, you meant that you had already learned two languages, and you specifically asked about the ".NET developer", which also implies someone who has learned at least one language. So, how should a .NET developer learn C ++? Answer: In the same way, he learned the other (s) languages โ€‹โ€‹that they know. If you learn best from books, get a book. If you learn how to better write a program, then do it. Use any methods that you have already proven to yourself.

In terms of content (not method), I suggest you learn about Visual C ++ / CLR, not just ANSI C ++, since your goal is to interact in the .NET environment. C ++ is well supported in the current .NET environment. There are quite a few differences, but I think you will be surprised how much this looks like C # or very similar to C #. I think you will also find that you do not need to learn the entire C ++ language to write interaction code. In fact, if your COM objects are small and simple, you may find that you can use a type library importer for interaction if for some reason you cannot or do not want to use C ++. There are some serious flaws and tradeoffs in this approach, so be sure to check out MSDN and MANY interop Q & A on stackoverflow for details.

0
source share

from the answer above ...

I think you will also find that you do not need to learn C ++ to write interaction code for both managed and unmanaged clients.

As you suggest, he writes an unmanaged client application in C #? (provided that you can show the C # assembly as COM visible, but this is not the same)

I think itโ€™s rather simplistic to mean that all your needs for interacting with COM are met by interacting with C #.

0
source share

All Articles