Is C++ an Object Oriented language?

2019-02-01 18:11发布

I have always heard that C++ is not Object Oriented but rather "C with Classes". So, when I mentioned to an interviewer that C++ was not really object oriented, he asked me why I didn't consider it an OO language. I haven't done any C++ since University, and I didn't have much of an answer. Is C++ Object Oriented or not? and why?

标签: c++ oop
18条回答
劫难
2楼-- · 2019-02-01 18:44

The term "object oriented" is too hazy to give a definite yes or no answer. I think you'll find the majority view is that C++ is an OO language, or at least that you can write in an OO way in C++. If you want a more definite answer, you'll have to ask a better defined question, such as:

Q: Does C++ have "object" (i.e. data fields + associated member functions) data types?
A: Yes.

Q: Does C++ have non-object data types?
A: Yes.

Q: Does C++ have non-member functions?
A: Yes.

查看更多
太酷不给撩
3楼-- · 2019-02-01 18:44

If I am an interviewer asking you this question, I'm probably not caring about the yes/no answer - I really want to know what you understand about programming, and C++ or other languages. Are you just throwing out terms that you don't think about or understand, or do you actually consider carefully what you are doing and saying. So in this situation a good answer is

"I define Object oriented coding to be a, b, c, and d. I define an Object Oriented language as one which supports that definition, ie. permits me to (easily / uniformly / rigorously / other adjective ) develop code that fulfills those requirements. C++ delivers a,b,c, and partially on d. So I do ( don't ) consider C++ to be OO for those reasons."

For my personal definition, C++ is object-oriented enough, plus it supports other approaches.

查看更多
手持菜刀,她持情操
4楼-- · 2019-02-01 18:47

Meh. Everybody has their own deinition of OOP. Alan Kay who invented the term OOP said: http://www.noulakaz.net/weblog/2007/02/12/true-meaning-of-oop/

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I’m not aware of them.

By that definition even Java, C#, Python etc are not OO languages.

IMHO, these discussions are pointless.

查看更多
Lonely孤独者°
5楼-- · 2019-02-01 18:49

C++ is an OO language.
But that is not the only style of coding that C++ can be used in. n As such C++ is technically a multiparadigm language of which OO is just one paradigm.

The term "C with classes" has a couple of meanings.

  • It can refer to the fact the C++ is OO (as classes give it the OO capabilities).
  • It can refer to the original version of "cfront"
    • Which was basically C with the extension of classes and little else.
  • It can refer (derogatorily) to a style of programming that does not utilize the full power of C++ but only uses a small subset of the language.
查看更多
在下西门庆
6楼-- · 2019-02-01 18:50

It is indeed object oriented but not strictly though.

Say for example, we can have just

int main()
{
 return 1;
}

which is nothing in the name of Object oriented and on the other hand we can have Classes, inheritance, polymorphism etc., that corresponds to Object Oriented.

It is up to us unleash the power of the language.

To the interviewer who asked you the question show a class a from C++ and ask him whether it is structured or procedured.. He will show you the same main() function I guess :)

So I guess it is based on what you have implemented that lies. But it has features that can make it to be considered as an OOP.

查看更多
beautiful°
7楼-- · 2019-02-01 18:52

C++ is not an object-orientated language. The language is not any paradigm. This is in constrast to Java, which is religiously object orientated (no friend statement, for example). C++ offers object orientation, but isn't inherently object-orientated.

查看更多
登录 后发表回答