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?

Flexo
  • 87,323
  • 22
  • 191
  • 272
  • 3
    it is considered three paradigm language here, http://en.wikipedia.org/wiki/Multi-paradigm_programming_language – idursun Jun 16 '09 at 07:55
  • 10
    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 Jun 16 '09 at 08:14
  • 1
    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 Jun 16 '09 at 09:11
  • If you get to this comment, please read paxdiablo's comment again. It is worth it. – Marco van de Voort Oct 26 '12 at 18:31

9 Answers9

15

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

unwind
  • 391,730
  • 64
  • 469
  • 606
9

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.

Degvik
  • 3,050
  • 6
  • 25
  • 20
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,

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89
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.

Sev
  • 15,401
  • 9
  • 56
  • 75
3

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

knittl
  • 246,190
  • 53
  • 318
  • 364
  • 2
    @JMSA: no, c# falls in the same category as java, c++, etc. if you want a full OOP language have a look at [smalltalk](http://en.wikipedia.org/wiki/Smalltalk) and similar – knittl Aug 10 '10 at 06:34
1

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.

pmr
  • 58,701
  • 10
  • 113
  • 156
  • 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 Jun 16 '09 at 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 Jun 16 '09 at 21:30
1

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.

Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
  • 2
    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#signatures – Shawn Chin Nov 22 '11 at 17:07
0

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

LeopardSkinPillBoxHat
  • 28,915
  • 15
  • 75
  • 111
  • 1
    Except that C++ does not require main to be a function. –  Jun 16 '09 at 07:56
  • @Neil: Then how else can you declare main()? – the_drow Jun 16 '09 at 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. –  Jun 16 '09 at 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

Aditya Sehgal
  • 2,867
  • 3
  • 27
  • 37