Except OOP, why is C++ better than C?
Why C++ is better than C? Besides the obvious list of features, in my opinion the real answer is that there's no good reason to still use C instead of C++. Even if you don't use OOP, you can use it as a better C. Even if you use just once a unique feature of C++ in your program, C++ is already a winner.
On the other hand, there's no disadvantage in using C++: it retains the performance goals of C and it is a quite low level language, while allowing very powerful things. And you will not miss any C feature using C++!
And don't forget the wide user base and the rich libraries and frameworks available.
By the way, C99 has added some interesting features but after a decade there's still very limited compiler support (so you are bound to ANSI C). In the meantime C++ evolved as well and the compiler vendors are committed to providing conforming implementations.
I'm a big fan of C
who over time has become a big fan of C++
. One of the big reasons for that is the STL ( the Standard Template Library ) and Boost.
Between the two of them it makes it very easy to write powerful portable applications.
Non-OO features that C++ has that C does not:
- Templates
- Function overloading
- References
- Namespaces
- You can use
struct
s andenum
s without writingstruct
orenum
before every declaration or using typedefs. - Even if you don't define your own classes, using C++'s string and container classes is still often more convenient and safe to work with than c-style strings and arrays.
- Type safety (even though some would call it weak)
- Exceptions
- Variable declarations in conditionals, C99 only has it in
for