Quote:
Originally Posted by hansel
- easier (and cleaner) initialisation of structs (constructors)
- better grouping of structs and corresponding functions
- constants instead of defines
- easier memory management (cleanup in destructors)
|
Especially if this are the only advantages who speak for picking c++ I'd really not do it (and have an application whose whole structure is not "class-like".)
For structs, you can just as well provide an "create_mystruct()" function for every structure you are doing, which allocats its memory and initialises it. I know there are some mroe things a c++ constructor can do. But for the uses here descriped create_mystruct() should do perfectly.
About grouping. This just needs coder discipline. And when I'd think yes the way for exmpale java does it, does group things better, by default especially c++ is there just a worse as c as you can provide the function implementation just anywhere. Only the defintition has to be with the structure. Not so hard to archieve with a little editor descipline also.
C has constants as well. Or at least as far as I know this is implemented exactly as good or worse than in c++.
Memory management also. If you don't have the descipline to be very careful when to allocate and destruct stuff, and when to destruct stuff when no parts of it are no longer being pointed to, c++ is only making things worse for you, as debugging just become a tad more difficult.
I like C, because everything you see is 99.9% like the processor behaves (as long you don't active gcc -O3), there is no magic happening anywhere. On the other hand in C++ the compiler does a lot of stuff in background. (Like calling destructors for a start, or duplicating code because of templates, or using pointers when you think you see it, (reference parameters); not calling destructors because you reference parametered a class and forget about it. Or calling a destructor while having a poitner to the class but run out of its context already. And so on. C++ is fine as long everything runs well, and you don't have to think about stuff really happening. But when things run wrong, using ddd is 100ooo times more exhausting...