| negative zero |
01-13-2013 03:46 AM |
Quote:
Originally Posted by felgall
(Post 1300162)
That is what C++ is all about. You use it to do object oriented programming.
|
It is impossible for a programming language to be purely object oriented, because object orientation is an abstract of the data structures. Data structures aren't the only language features of a programming language required to express algorithms. Consider while and for loops, which are procedural elements. C++ also has lambdas, which are functional elements.
Quote:
Originally Posted by felgall
If you just wanted to write procedural programs then you would use C rather than C++ because C++ is C with the additions needed to be able to write OOP.
|
... Unless you wanted the other features that C++ offers, eg. lambdas, static typing, smart pointers, exceptions, reference types, etc.
C++ is not an extension of C. That may have been true in 1985, but since then there have been numerous features added to both programming languages that haven't been synchronised, some of which clash. For example, C uses a less static type safety than C++. The modulo operator isn't required to behave identically when handling a negative denominator. In C++, sizeof 'a' is 1 where in C, sizeof 'a' is sizeof (int). C has the addition of variable length arrays and flexible array members which C++ doesn't have. The list goes on...
Quote:
Originally Posted by felgall
The advantages to writing OOP with C++ are the same as writing OOP in any other programming language - it makes it easier to break big programs up into manageable sections and to reuse code in multiple programs - by defining objects that not only contain all of the data associated with a particular object but also all the code to handle all the different things you can do with that object.
|
Have you ever studied the Liskov Substitution Principle? I would suggest that proper OOP is quite a restrictive form of abstaction.
As for an answer to this question, I'll quote a user from another forum. Rest assure I have permission to do so.
Quote:
Originally Posted by Seb
Object orientation is an abstraction. Consider the definition of car, which is a category that consists of all things with four wheels, gears, an engine and a steering wheel, among other things. This is an abstract definition of a car.
The "car" might define a method called "stear" or "turn", which is an action if you like, that an instance of a car can perform to change it's own direction or bearing. According to Liskov substitution principle, it would be incorrect to define a "drive" method in "car" because manuals drive differently to automatics.
By inheritance, derivations such as "automatic car" and "manual car" can be defined to re-use and extend the properties of the "car". The two extensions can then implement their own "drive" or "accelerate" methods, etc. Other projects can then reuse these implementations. That's the idea behind abstraction.
One of the only things that the community of OOP programmers can agree upon is that any code that uses "car" correctly should be able to use "automatic car" and "manual car" in it's place without any problems or differences in functionality. ...
|
The rest of the post assumes lack of specifics regarding the language. I won't provide further specifics regarding C++, because this is a pretty good answer to your question. If you have more questions, feel free to ask them.
|