In windows 8 you can program in c++ however it is an interesting dialect of c++. There are no naked pointers. Instead they have what is really just a shared_ptr operator ^ .
This means there are absolutely no memory leaks in their version of c++. You can do this without using windows 8 if you wish. So you get the best part of C# in c++. It is rather genius I might add. And there is no need for garbage collection, everything is deleted properly. There is no garbage collector, and everything runs very fast.
The "^" operator isn't equivalent to a shared_ptr (if it were, you would have a ton of leaks, because shared_ptr's can't cope with circular references, and require the programmer to be able to explicitly choose between them and weak_ptrs...), it's exactly equivalent to C# references!
The dialect you're talking about is called C++/CLI, and it is compiled to MSIL -- the same intermediate "bytecode" language that C# is compiled to, and it runs on the same VM and uses the same Garbage Collector that C# does!
Scratch that!
The OP (and many others) have just made the assumption that C# is slower or more cumbersome. I heard the same thing in the 90s that C++ was bloated and more cumbersome than C. I read the same arguments in the 80's that C was painfully slow and could never replace the skilled assembly-writing artisan.
This is true, but what changed? Computers got faster, much faster and the cost of the more expensive language features became affordable.
What changed is that C compilers got smarter and smarter, to the point where they can now write assembly as well as experts can (when given sensible inputs). Likewise, C++ compilers got smarter and smarter, to the point where they matched C compilers.
Following the same tradition, C# compilers are also getting smarter.
Take note that because C# is a lot more restrictive on the programmer, operating on a completely different kind of 'abstract machine' to C/C++, the compiler actually has a lot more information available to it when making optimisation decisions.
e.g. C++ code can look pretty innocent, but still cause a lot of confusion for the compiler. As a straw-man, take this function:
void World::FindPlayerWithMinHealth( int& outHealth, int& outIndex )
{
outIndex = -1;
outHealth = 100;
for( int i = 0; i != m_players.size(); ++i )
{
if( m_players[i].health <= outHealth )
{
outIndex = i;
outHealth = m_players[i].health;
}
}
}
And then I call it with:
world.FindPlayerWithMinHealth( world.m_players.m_size, world.m_players.m_size );
When the compiler is compiling the function, it has to do it in such a way that the stupid line above will behave as expected. So, looking at it again:
void World::FindPlayerWithMinHealth( int& outHealth, int& outIndex )
{//these two lines could change any bit of memory anywhere in the system!!
outIndex = -1;
outHealth = 100;
for( int i = 0; i != m_players.size(); ++i )//m_players.size() has to be re-called every iteration, perhaps it's value has changed.
{
if( m_players[i].health <= outHealth )//have to fetch m_players.begin every iteration, perhaps it's value has changed
{//these two lines could change any bit of memory anywhere in the system!!
outIndex = i;
outHealth = m_players[i].health;//have to fetch m_players[i].health again, even though it just appeared above.
}
}
}