views:

294

answers:

5

I hope this question is not too silly, but what is the most basic class in standard C++? object? Object?

class MyObject : public object{  ...

and I get "Expected class-name before token{"

Is there any map, diagram or image that shows standard c++ classes inheritance? Something like this but for C++ ?

+9  A: 

There is no fundamental object type in C++, unlike in e.g. Java.

Oli Charlesworth
+14  A: 

There is no most basic class in C++ i.e. there is no common base class for all the classes.

Naveen
+3  A: 

This is the simplest most basic class you can compile:

class Null
{
};
sashang
Though it can't safely be a public base class.
GMan
+3  A: 

Inheritance diagram for IOstream library is here. STL is a template library and doesn't use OOP.

Sure it does, it has classes and polymorphism.
GMan
Actually STL _does_ use OOP - heavily. It uses templates _on top of_ OOP, but it does use OOP.
utnapistim
No, STL doesn't use OOP. Don't confuse Object Based Programmings with Object Oriented Programming. Yes, STL containers are objects. But you won't find any virtual functions to overwrite. Containers don't have virtual destructors, so that you can't use them as polymorphic base classes.
@rn141: I think this may be a dichotomy that you've invented! The inability to safely inherit doesn't mean that you don't have OOP. At any rate, the innards of STL uses plenty of inheritance (`reverse_iterator` inherits from `iterator`, and so on).
Oli Charlesworth
Everyone defines OOP differently. I think the person who started this question was looking for Java style inheritance/OOP hierarchy for C++ standard library classes. In that sense, STL isn't OOP, no matter what the innards of STL uses. Unlike typical Java library, STL provides us with models which implement certain concepts. We don't care what inherites what. Unlike typical Java library, STL isn't built around IS A relationship.
@rn141: I just gave you an example of an "is a" that is exposed in the interface to STL! There are plenty of others. I'm not sure by what measure this "isn't OOP"!
Oli Charlesworth
It is very different from Java, where everything is virtual and you can overwrite pretty much every function. I have never seen any code which uses reverse_iterator as ISA iterator. If you implement STL without inheriting reverse_iterator from iterator, 99.9% of existing C++ code will work fine. STL classes aren't designed to be used polymorphically. Polymorphism is a central figure in OOP and it is absent from STL.
Except that it's defined as such in the C++ standard. Any code can be rewritten to not use polymorphism; that doesn't make it non-OO. Java isn't the definition of OOP!
Oli Charlesworth
You are refuting something I didn't state. Open any OOP book and you will see polymorphism, virtual functions, interfaces, abstract base classes, etc everywhere. Non of it really matters to the STL users. Even IOstream library is not used in polymorphic fashion. Look into Gang of Four book (the modern day OPP Bible for all practical purposes) and tell me how it is related to STL? The original question is asking about granddaddy of all C++ classes. Typical OOP approach to building libraries. There is no such thing in STL.
We'll have to agree to disgaree, because you are arguing a very strange point; that STL isn't OO because it doesn't use certain features.
Oli Charlesworth
I look from the user's point of view. STL is called "template library" for a reason. STL is an example of generic programming, not OOP programming. How STL is implemented isn't that important to the users. In fact, no STL implementation uses OOP design patterns for its internals. When using STL we care about concepts such as default constructable, copy constructable, assignable, comparable, etc. OOP is about interfaces and virtual functions. Alex Stepanov, the creator of STL, doesn't consider it as OOP. Read Stepanov's interview, if you care.
@m141: "Even IOstream library is not used in polymorphic fashion." -- Yes it is. Any time you implement `operator<<` or `operator>>` and take `iostream` as the first parameter, you're invoking static polymorhism. Just because the interface doesn't expose `virtual` functions doesn't mean it's not polymorphic.
greyfade
@rn141: `streambuf` completely depends on virtual functions and inheritance. Don't commit the No True Scotsman fallacy.
GMan
There is not much OOP form the user's perspective. We are not talking about the inner workings of IOstream, right? How operator<< is implemented is not user's concern. Typical OOP library/framework provides users with interfaces and base classes. One needs to inherited/overwrite virtual functions to plug his own classes into the framework. That is OOP and it is not how 99.9% of users use IOstream. To them IOstream is a library which takes care of low level stuff. Every IOstream object is pretty much unique. Compare it to ACE or typical Java library. See the difference?
@rn141 your understanding of what an interface is seems to be limited to java. "An interface is a common boundary or interconnection between systems" (taken from dictionary.reference.com). Template classes require you to implement a number of methods to use them, the interface is implicit. Which is good since primitive types can't "inherit" and could not be used with those templates - a big problem of java generics, they can't deal with primitive types. Back to the point the interface is there, it just isn't a java interface.
josefx
Pounding a straw man? The original question asked if there is a common base class for all C++ classes. Clearly, the person comes from Java and he wants to know if there is something similar in C++. From the context it is perfectly clear what I mean by interface and why it is pertinent to the original question. Please don't pretend that your definition of interface is carved in stone and everyone goes by it. Basic notions such as interface, object, etc are hard to define outside the context they are used.
@rn141 I have been responding to your claim that the stl does not use Object oriented programming. If your definition of OOP is limited virtual inheritance then you may be right, but in my opinion there is more to OOP.
josefx
I understand 1st and 2 comments. After that I made it clear that I was looking from the user's perspective. Alex Stepanov, the creator of STL, doesn't consider it OOP. To the user even IOstream isn't OOP, unless he wants to do some low level stuff. Widely sited OOP book is "Design patterns" by Gamma et. al. It is often referred as Gang of Four and considered a bible by many OOP programmers. But non of Gang of Four really matters to STL. Most of C++ programmers learn how use IOstream long before they start bothering with Gang of Four. To them IOstream isn't about OOP as well.
+6  A: 

In Cocoa, the NSObject class is fundamental to the framework but not to the Objective-C language itself. In Objective-C, it is possible to create a root class by not deriving from anything (but in order to make it work you'll probably have to hack your way through runtime calls).

Similarly, some C++-based frameworks may define a root class that all other classes in that framework derive from, but it is specific to the framework, not the language.

dreamlax