tags:

views:

1020

answers:

8

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

+1  A: 

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.)

dirkgently
"Yes, I do know Java supports FP.". That's new to me. Do you have any example of FP in Java?
Rafa Castaneda
A simple search gets me quite a few articles. One such: <http://www.ddj.com/java/184406320;jsessionid=NEAFYLK3RWELXQE1GHPCKH4ATMY32JVN?_requestid=113713>
dirkgently
+3  A: 

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

Steve Gilham
+12  A: 

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.)

JXG
A: 

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.

reko_t
Neither of those are as primitive datatypes do not obey the same semantics as user defined datatypes. Operations on them are not defined in terms of passing messages and they cannot be overloaded or redefined in a derived class.
Omnifarious
I think you commented the wrong post. ;)
reko_t
No, Omni is saying that neither C# nor Java are pure OO since they have things like int and long which are *not* objects.
paxdiablo
A: 

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.

Omnifarious
A: 

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).

Dror Helper
+1  A: 

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 :-)

paxdiablo
Dont actually need main. Its just a well known entry point so command line and (some) GUIs no where to pass control to after load.
James Anderson
You *do* need main, it's mandated by the standard.
paxdiablo
A: 

of course not!! It supports intrinsic data types.

the69geeks