I have been developing a project that I absolutely must develop part-way in C++. I need develop a wrapper and expose some C++ functionality into my C# app. I have been a C# engineer since the near-beginning of .NET, and have had very little experience in C++. It still looks very foreign to me when attempting to understand the syntax.
Is there anything that is going to knock me off my feet that would prevent me from just picking up C++ and going for it?
C++ has so many gotchas that I can't enumerate them all. Do a search for "C# vs C++". A few basic things to know:
In C++:
- struct and a class are basically the same thing (Default visibility for a struct is public, it's private for a class).
- Both struct and class can be created either on the heap or the stack.
- You have to manage the heap yourself. If you create something with "new", you have to delete it manually at some point.
- If performance isn't an issue and you have very little data to move around, you can avoid the memory management issue by having everything on the stack and using references (& operator).
- Learn to deal with .h and .cpp. Unresolved external can be you worse nightmare.
- You shouldn't call a virtual method from a constructor. The compiler will never tell you so I do.
- Switch case doesn't enforce "break" and go thru by default.
- There is not such a thing as an interface. Instead, you have class with pure virtual methods.
- C++ aficionados are dangerous people living in cave and surviving on the fresh blood of C#/java programmers. Talk with them about their favorite language carefully.
Garbage collection!
Remember that everytime you new
an object, you must be responsible for calling delete
.