This is a very general question. I’m a self taught ‘programmer’ who programs in C#. A project I would like to work on would be made a whole lot easier (in the grand scheme of things) if I knew C++. How easy is it to move from C# to C++? Any pitfalls I should watch out for? And if I am using VS2010, can I program (not in the same class, but same project) something in both C# and C++?
Share
Moving from C# to C++ is not easy. The basic syntax can appear the same (e.g. if, for…), but there are deep differences, e.g. the RAII pattern and stack-semantics variables whose destructors are called when they go out of scope, etc. are not present in C#.
Moreover, C# uses a non-deterministic garbage collector (which can be OK for memory resources, but is useless for other kind of resources). Instead, with modern C++, you can use templates and smart pointers (like std::/boost::*shared_ptr*), which allow you to have deterministic reference-counted “garbage collection”, which is very efficient, and is valid for both memory and non-memory resources (like file handles, sockets, textures…).
Moreover, the C# generics are very different from C++ templates (C++ templates are very powerful, and allow an advanced level of programming called template meta-programming).
In VS2010 you can have a solution hosting both C++ and C# projects. To communicate between the two worlds (the native world of C++ and the managed world of .NET/C#) you can use C++/CLI as a kind of bridging layer.
In Windows 8 a new technology should be introduced, called WinRT (based on COM), which allows inter-language communication. In this case, you can use C++ with WRL (a template-based library) or C++/CX language extensions to build C++ components that can be used from C# and .NET.
Happy learning.