You aren't using it now, but the next time you leak memory or get a double delete, you'll be begging to come back to std::vector<T>
, std::unique_ptr<T, Del>
and std::shared_ptr<T>
, which can solve those problems easily- almost trivially. That's what happens to everyone who uses C over C++, eventually, and the smarter ones just don't wait for the bugs to pop up before moving over.
Code that uses new
and delete
directly doesn't really belong in C++, it belongs in that kind of half house that we refer to as "C with Classes". That's where the language was circa 1985. It's not particularly similar to C++, circa 2011. In all likelihood, wherever you learned C++ simply didn't teach it very well- something that is unfortunately rather common- and with a better education, you would find use of these features.
Specifically, as I listed above, C++'s generic data structures and the resource-managing classes simply are fundamentally massively superior to anything C has to offer. If you want a dynamically allocated array, then use std::vector<T>
. That's a pretty common use case. If you aren't using them, then your code is at huge risk of error unnecessarily- especially resource management related. C++ can guarantee safety and re-use code in a way that C can never touch.
However, I think that you also might be expecting too much. Writing templates and operator overloads is not common for library consumers. If your code uses std::vector<T>
, you don't need to write a template to make that happen. If your code uses std::string
, nobody is forcing you to overload your operators. You only have to do those things to write std::vector<T>
and std::string
- but you can still take full advantage of them.
Polymorphism/inheritance also only has a specific use case. If your code happens to not require you to write any templates or use virtual functions, then it doesn't, and there are programs or segments of programs where you don't need to write your own templates.
Also, there's no gain in performance in C over C++.
In terms of OO design, you don't have to change all that much when going from Java to C++. The majority of the design principles is actually language independent and applicable to both Java and C++.
How you express your design in code can differ quite a bit between languages. The most important thing to remember is C++ does not have automatic garbage collection. That and the fact that any C++ object can be created without using new
are the two driving factors behind the differences in expressing your design in C++ or Java code.
In particular, it is very common in C++ to express composition by directly having a member of type X in class Y without involving a pointer.
More in general, if you can avoid dynamic memory allocation in C++, do so. If you can't, see if there is a smart pointer available that can ensure the memory is released again at the right moment.
Best Answer
No. This is woefully and terribly misguided.