Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > super superclass

Reply
Thread Tools

super superclass

 
 
bob@coolfone.comze.com
Guest
Posts: n/a
 
      04-17-2012
In C++, is there a class like the Java Object class that all classes derive from?
 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      04-17-2012
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> In C++, is there a class like the Java Object class that all classes
> derive from?


No.

Now depending on what you want to use Object for, there may still be
ways to accomplish it.
 
Reply With Quote
 
 
 
 
Christopher Pisz
Guest
Posts: n/a
 
      04-18-2012
On 4/17/2012 8:50 AM, (E-Mail Removed) wrote:
> In C++, is there a class like the Java Object class that all classes derive from?



I've seen a good number of people coming from java that decided to roll
their own in C++, and more times then not, it ends up causing problems.

Instead, decide what you need a particular class to do, or group of
classes. You are in the danger zone when you start thinking along the
lines of "All classes should do X."

For example, do all classes really need a ToString() method? Surely,
there are going to be some classes where a string representation either
makes no sense or has little value. However, it might make sense to have
some common method like ToXml() for all configuration classes....




 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      04-18-2012
On Wed, 2012-04-18, Christopher Pisz wrote:
> On 4/17/2012 8:50 AM, (E-Mail Removed) wrote:
>> In C++, is there a class like the Java Object class
>> that all classes derive from?

>
> I've seen a good number of people coming from java that decided to roll
> their own in C++, and more times then not, it ends up causing problems.


That's what Stroustrup calls "don't use C++ as if it was Smalltalk",
and he's warned against it countless times.

(We don't know why the OP asked, though. He didn't say he wanted to
use such a design.)

....
> For example, do all classes really need a ToString() method? Surely,
> there are going to be some classes where a string representation either
> makes no sense or has little value.


Unfortunate example, since the standard way to do this in C++ is to
provide a ostream << Foo overload. No common superclass needed.

> However, it might make sense to have
> some common method like ToXml() for all configuration classes....


/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      04-19-2012
On Wed, 18 Apr 2012 22:07:47 +0000, Jorgen Grahn wrote:

>> For example, do all classes really need a ToString() method? Surely,
>> there are going to be some classes where a string representation either
>> makes no sense or has little value.

>
> Unfortunate example, since the standard way to do this in C++ is to
> provide a ostream << Foo overload. No common superclass needed.


But that will dispatch according to the static (compile-time) type, not
the dynamic (run-time) type.

 
Reply With Quote
 
Pavel
Guest
Posts: n/a
 
      04-20-2012
(E-Mail Removed) wrote:
> In C++, is there a class like the Java Object class that all classes derive from?


Technically, no.. but Qt's QObject comes close .

See http://qt-project.org/doc/qt-4.8/qobject.html#details.

HTH
Pavel
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      04-20-2012
On Thu, 2012-04-19, Nobody wrote:
> On Wed, 18 Apr 2012 22:07:47 +0000, Jorgen Grahn wrote:
>
>>> For example, do all classes really need a ToString() method? Surely,
>>> there are going to be some classes where a string representation either
>>> makes no sense or has little value.

>>
>> Unfortunate example, since the standard way to do this in C++ is to
>> provide a ostream << Foo overload. No common superclass needed.

>
> But that will dispatch according to the static (compile-time) type, not
> the dynamic (run-time) type.


Yes, but is that a problem? It just has to be implemented differently
for those types:

std:stream& operator<< (std:stream& os, const SomeSuperClass& val)
{
return val.put(os);
}

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if another object is my superclass from a function in aneven higher superclass? bart van deenen C++ 6 03-03-2009 02:44 PM
super() doesn't get superclass Ben Finney Python 53 09-20-2007 04:56 PM
calling superclass __init__ when superclass is object Evan Klitzke Python 0 08-02-2007 05:15 AM
class 'Exception', unable to use 'super' to call superclass initializer chriss Python 3 09-10-2005 09:53 PM
super.super.super how? Java 24 02-24-2005 10:51 PM



Advertisments