Why not c with classes?

I'm sure many of you have already read the title and want to punch me for asking this but, what's wrong with the "c with classes" style of c++? I'm mainly a c programmer with some java background, and the only reason I would move to c++ is to get object orientation(you know, data hiding and other stuff that, although it can be implemented in c, it looks a little hackish).

So if I moved to c++ I would prefer to just use the features I'm interested in(that is, classes, abstract classes and interfaces), but I've read topics all over the place saying that c++ is not c with classes and should not be used like so.

What do you guys think? Would it be somehow counter-productive? What would it mean to use c++ and not c with classes?
People who say "C++ is not C with classes" are saying what they want the truth to be... not what the truth actually is. C++ is C with classes, and this truth is - frankly - the biggest weakness of the language. There are thousands of (generally legacy) codebases that use C++ as C with classes, and they all work just fine. Using C++ in this way is not intrinsically counter-productive.

The part that gets peopled riled up about what you're describing is writing primarily procedural code. This is an inevitable outcome of using "C with classes," and isn't really the "norm" in today's engineering world. Will it slow you down or be counter-productive? Not if you know when to fall back into classes (polymorphism, inheritance, encapsulation). If you don't know when classes become appropriate, this approach may very well slow you down.
Well, it is true that C++ is not just C + classes. Some valid C programs will not compile as C++ programs.
I can't remember which chapter of scott Meyers's book this question reminded me of so I've just had a quick google and found this:
http://www.codeproject.com/Articles/713401/View-Cplusplus-as-a-Federation-of-Languages

It might be of interest.
what's wrong with the "c with classes" style of c++?

C++ gives you far more than only classes, that's why it's wrong to call it C with classes.

I'm mainly a c programmer with some java background, and the only reason I would move to c++ is to get object orientation

You can get far more out of C++ than that.
Generic programming in C++ is far more advanced than in C (i remember working with void* a while ago and that sucks...).
There are some numeric and non-numeric algorithms that you can use with your own container (or you can use the stl-containers which are pretty good themselves).

Furthermore in C++11 there are 3 classes in the standard library for automatic memory management (shared_ptr, unique_ptr, weak_ptr).
If you don't want to use C++11 features there is also a class called auto_ptr in the old C++ standard (which is now deprecated because of the new ones).

C++11 also introduced a standard threading library.


It's up to you to decide what you do but c++ provides far more facilities than c.
@Gamer2015

I was not saying that c++ IS c with classes, I meant that if I used c++ I would only use classes and the standard c library. Mostly because I like to keep it simple, and c++ feels like it's bloated, the standard library is huge, it has a lot of useful but not necessary stuff(as far as I can tell). But I feel like doing so could be a bad thing because people seem to complain about c++ programs that don't make full use of templates, exceptions, etc, etc.
because people seem to complain about c++ programs that don't make full use of templates, exceptions, etc, etc.

Nah, you don't have to use everything.
Templates and exceptions can be abused like anything else.
To be honest I try to use those exception handeling as little as possible and I practically never use templates.
When I do something where I need exceptions i write a base-library which does all the exception handeling stuff so that I don't have to care about that anymore.
When I need templates I write a class that contains all operations I need so that I don't have to think about it anymore.

Don't get me wrong, I still have a pretty good understanding of them.

Mostly because I like to keep it simple, and c++ feels like it's bloated, the standard library is huge, it has a lot of useful but not necessary stuff(as far as I can tell)

Yeah, the C++ standard library is huge and has lot of useful stuff.
To be honest you don't need anything (except type_traits for templates) in there because you can make (nearly) everything yourself because most of the c++ standard library is written in C++.
However I like the standard library because it has many features that I can make use of.

Streams are amazing for formatted input/output operations.
std::vector is an amazing dynamic generic container.
std::string is an amazing class for handling text. (far surpirior to c-strings)
std::shared_ptr is amazing for memory-management
You can write your own container class and use the algorithms with little effort.

I am not saying that you have to use them but when writing code in c++ your code might get clearer and easier to read when you use some features of the standard-library.
Last edited on
Well in that case, I'll have a look at c++. I think I'll only be using classes and overloading, but maybe some of the libraries may come in handy. Thanks!
Remember you don't have to include ALL of the STL.
when you do something like this:

 
#include<vector> 


you are only including the vector stuff, not the entire STL. It's all in the std namespace, but split over many many files, which is good. And you don't get namespaces in C :)
Last edited on
Topic archived. No new replies allowed.