Is C++ completely object oriented language?

2020-05-23 06:39发布

问题:

I read about small talk being completely object oriented.. is C++ also completely object oriented? if no.. then why so??

回答1:

No, it isn't. You can write a valid, well-coded, excellently-styled C++ program without using an object even once.

C++ supports object-oriented programming, but OO is not intrinsic to the language. In fact, the main function isn't a member of an object.

In smalltalk or Java, you can't tie your shoes (or write "Hello, world") without at least one class.

(Of course, one can argue about Java being a completely object-oriented language too, because its primitives (say, int) are not objects.)



回答2:

C++ contains a 'C' dialect as a subset, permitting a purely procedural style of code.



回答3:

The big arguments people have against declaring C++ as "pure" OO is that it still requires at least one non-OO bit, main(), and that not everything is an object (int, long et al).

It also exposes the state of an object for manipulation without using the message-passing paradigm (public members). This breaks the encapsulation of objects.

Java, on the other hand, has main() as just a static method of a class so it's closer but it still has non-object things in it.

Smalltalk is the lingua franca normally held up as the purest of the pure, but I don't know enough about it to comment.

Me, I tend to leave those sort of arguments for the intelligentsia while I get on with developing code and delivering to my clients :-)



回答4:

Define OOL. If you mean using classes etc, then C++ supports OO-style of programming among others. There's nothing that stops you from not using classes. Java OTOH, does not allow for but classes. (Yes, I do know Java supports FP.)



回答5:

The short answer is no - C++ is not entirely OO language. You can write "not exactly" OOP using C++ even without resorting to using the C subset. One such example is your main method - which is not contained in any class.

The main reason is the fact that C++ originated from C - when Stroustrup created the language he was aiming to create a new version of C (with classes). in fact he have tried to submit his creation as the new flavor of C (C84).



回答6:

C++ is not a pure object oriented language, and as already mentioned nothing forces you to use OOP concepts in C++. C++ is what you call a hybrid object oriented language, as it's based on C which is purely a procedural language.

Examples of pure object oriented languages are C# and JAVA.



回答7:

No, it is not a purely object oriented language. In particular primitive datatypes in C++ have rules that are frequently different from datatypes that aren't primitive. Additionally it is possible to have functions that are not associated with any datatype at all. There are a myriad of other ways in which C++ is not a pure object oriented language, but those are two of the biggest reasons.

Neither Java nor C# are pure object oriented languages either because they have primitive datatypes that do not obey the same semantics as 'object' datatypes.



回答8:

of course not!! It supports intrinsic data types.



回答9:

C++ is nothing but "C with classes". I can still write a C program and save it as .cpp file. So, Proof by implication says "C++ is not a purely object oriented language."



回答10:

The reason why C++ is not a OOP language is mainly because it is missing the concept of encapsulation. You can't define an interface/contract to your object because of the pointers which give you total control on everything.



标签: c++ oop