4 ms·
You almost never use `new` in modern C++, and you would never use it as you suggest because it wouldn't compile, you would simply say: MyType x; C++ is n
by zabzonk 7y ago
You almost never use `new` in modern C++, and you would never use it as you suggest because it wouldn't compile, you would simply say:
MyType x;
C++ is nothing at all like Java.
- tombert 7y agoSorry, you'd need to use the MyType* x to use the `new` keyword; it's been awhile. It doesn't really deter from my point though; in order to heap-allocate something you have to use a pointer, and you end up doing something not that dissimilar from Java. > C++ is nothing at all like Java. Is that supposed to be a joke? Java was marketed specifically towards C++ engineers...
- saagarjha 7y ago> in order to heap-allocate something you have to use a pointer Usually the heap allocation is hidden behind a handle.
- pjmlp 7y agoNot on the libraries I usually have to touch. I would already be happy when I am allowed to re-write some of it into C++11.
- iainmerrick 7y agoJavascript was marketed towards Java programmers, and those languages are pretty different from each other too.
- tombert 7y agoI would say that C++ is closer to Java than JavaScript is; it's fairly easy to copy-paste and edit C++ code into a Java file with, just changing a small amount of syntax and get rid of the manual memory allocations. Try copy-pasting JS into a Java file, and there are semantics there that are completely foreign; you can't simply translate it.
- iainmerrick 7y agoI agree that JS and Java are very different; that was my point. I disagree about Java and C++. If I have a C++ file that uses RAII or references, for example, it won’t translate to Java easily. And those aren’t unusual, they’re both common techniques.
- pjmlp 7y agoYep, indeed. https://docs.microsoft.com/en-us/cpp/mfc/class-library-overview?view=vs-2019 https://docs.microsoft.com/en-us/cpp/mfc/class-library-overv... https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/ https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-a... http://docwiki.embarcadero.com/Libraries/Rio/en/Main_Page http://docwiki.embarcadero.com/Libraries/Rio/en/Main_Page https://doc.qt.io/ https://doc.qt.io/ https://docs.unrealengine.com/en-US/Programming/Introduction/index.html https://docs.unrealengine.com/en-US/Programming/Introduction... https://docs.cryengine.com/display/SDKDOC2/Home https://docs.cryengine.com/display/SDKDOC2/Home There is the "Modern C++" described at C++ conference talks and then what everyone else uses.