Is C++ not a fully OOP Language?

Go To StackoverFlow.com

3

I know that in OOP we have to declare everything e.g. variables, functions, etc. inside a class like in Java, but in C++ we can declare outside the class too.

Is this the reason that, C++ is not fully OOP? Or is there anything else?

2009-06-16 07:50
by NoName
it is considered three paradigm language here, http://en.wikipedia.org/wiki/Multi-paradigmprogramminglanguag - idursun 2009-06-16 07:55
By your reasoning, Java is not fully OOP either. There's nothing even remotely object-y about an int. And that main() being inside a class is just black-magic trickery. If you really want pure OO, just head on over to the Smalltalk ghetto :- - paxdiablo 2009-06-16 08:14
It is the developers choice. C++ can be pure OO if desired. But if OO does not cover all your needs then you use the other paradigms supported by C++ - Martin York 2009-06-16 09:11
If you get to this comment, please read paxdiablo's comment again. It is worth it - Marco van de Voort 2012-10-26 18:31


14

Huh? C++ is a hybrid, multi-paradigm language. It is certainly not a "pure" object-oriented language, where "everything is an object" holds true. C++ supports classes, objects, encapsulation, and so on, but since it's also (more or less) backwards-compatible with a lot of C code, it cannot be "fully object-oriented".

2009-06-16 07:52
by unwind


7

Object-Oriented Programming is not definition of the language, it's definition of the programming, a program. I.e. one program in C++ can be OOP, and other can be not OOP.

What you can say is that C++ fully supports means of programming in OOP paradigm.

2009-06-16 07:59
by Degvik


6

Define fully OOP? There are as many opinions as people probably

Note as far as purity goes, IIRC all languages with valuetypes are not "pure" in the strict sense. No, boxing doesn't count.

Over the years, in discussion I've tried to go back to the core OOP features:

  • identity
  • Classification
  • polymorphism (not inheritance, since some OOP have no inheritance)
  • encapsulation

So if you can tell if two classes are not the same class (identity), you can make the classic "duck quacks" and "dog barks" example (to demonstrate inheritance/polymorphism and classification) and you can hide fields, you are pretty much there.

Applying it to all the languages is more difficult though. While I do get functional programming roughly, I'm not trained enough in the their near infinite jargon to judge all those functional-oop-imperative hybrids that are springing up,

2009-06-16 07:52
by Marco van de Voort
I'd even guess opinions > people. ; - Adrian Grigore 2009-06-16 07:53
Quite possibly... mine has changed a bit over the years : - workmad3 2009-06-16 07:54
@Adrian: especially if some of them have more than one user : - Daniel Daranas 2009-06-16 08:20


3

In C++ you don't HAVE to code using OOP, you can choose not to use it. Having said that, it's "fully OOP", OOP is just just not a requirement.

2009-06-16 07:53
by Sev


3

not even java is a full OOP language.
in real OOP languages everything is an object, conditionals, loops, etc.

2009-06-16 08:11
by knittl
"not even java is a full OOP language"??? How? Then how about C# - user366312 2010-08-10 04:46
@JMSA: no, c# falls in the same category as java, c++, etc. if you want a full OOP language have a look at smalltalk and simila - knittl 2010-08-10 06:34


0

The main() function is not inside a class, so for this reason, one could argue that C++ is not fully OOP.

2009-06-16 07:54
by LeopardSkinPillBoxHat
Except that C++ does not require main to be a function - NoName 2009-06-16 07:56
@Neil: Then how else can you declare main() - the_drow 2009-06-16 08:16
You can't declare main. The compiler is permitted to implement it as it sees fit. You are also (unlike in C) not permitted to call it, because it may not be a function - NoName 2009-06-16 08:33


0

One of the reason C++ is not fully OOP is the requirement of backward compatibility with a lot of C code. Built in types are not Objects in C++ as it is less efficient if they were. Remember, C++ first target audience were existing C programmers and efficiency was (is) a great concern.

However, C++ supports all the important features of OOP.

Related Link : www.research.att.com/~bs/oopsla.pdf

2009-06-16 08:00
by Aditya Sehgal
One could as well say Java isn't fully OOP because it supports valuetypes - Marco van de Voort 2009-06-16 08:03
If fully OOP == "everything should be an object", then yes java is also not fully OOP. In my opinion, everything should be an Object is a loose way to define OOP - Aditya Sehgal 2009-06-16 08:10
Note that the valuetype argument is just one I know from similar internal debates in our UUG. Not necessarily my opinion. IMHO the problem is in the question, not the answe - Marco van de Voort 2009-06-16 08:14
Exactly. C++ satisfies enough OO Principles to qualify as fully OOP. I alaways figure that the valuetype argument is just a technicality or an implementation decision - Aditya Sehgal 2009-06-16 08:18
It keeps the Java and C# people of your neck :- - Marco van de Voort 2009-06-16 08:20


0

Even though the question is somewhat ugly phrased I'm not really satisfied with all the answers provdided yet. I preffer to think of languages as "supporting a paradigm" and not "being in a paradigm". So, when does a language support a paradigm? When it is easy to write code that satisifies the requirements of the paradigm. How one comes to this conclusion? Consider the style linux filesystems are implemented. It is C-Code that clearly has OO properties. So, would you not consider this code to be OOP because C is not a OOP-language? I don't think so. (I guess some people will rightfully disagree as this seems to be amtter of opinion.) What does this imply for C++? Well, C++ has a lot of facilities for making it easier to program in a OO-Style, but it also provides you with a lot of means to rape the paradigm and write code that looks OO (because you use classes, inheritance private variables) but completly violates some other OO-principles (e.g. single responsibility, open-closed, uniform access).

I would conclude that C++ supports the OO-paradigm to some extent but is clearly inferior to some of the modern OO languages.

2009-06-16 08:20
by pmr
OOP modelling and OOP languages are not the same thing, as the C example demonstrates.

Do you have a reference for those OO principles? I could only find the ones listed above. People add features "in the spirit of OO" all the time, but that can also be to create an unique selling point for their own so perfect language - Marco van de Voort 2009-06-16 08:46

Personally, if I talk about "OO principles" I mean the ones descriped in "Object-Oriented- Software Construction" by Bertrand Meyer. http://stackoverflow.com/questions/399656/are-there-any-rules-for-oop gives an overview as well - pmr 2009-06-16 21:30


0

The main concept of OOP is that every member in an object oriented programming language should be defined inside of the class, whereas in c++ the main function is defined outside of a class. That is why c++ is not fully object oriented programming language.

2011-11-22 16:53
by ALOK KUMAR mca sathyabama univ
welcome to stackoverflow. FYI, you don't need to leave a signature for all your posts. That's what the user card is for. See http://stackoverflow.com/faq#signature - Shawn Chin 2011-11-22 17:07
Ads