Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15427 > unrolled thread
| Started by | bob@coolfone.comze.com |
|---|---|
| First post | 2012-04-17 06:50 -0700 |
| Last post | 2012-04-20 00:29 -0400 |
| Articles | 7 — 6 participants |
Back to article view | Back to comp.lang.c++
super superclass bob@coolfone.comze.com - 2012-04-17 06:50 -0700
Re: super superclass Marc <marc.glisse@gmail.com> - 2012-04-17 14:29 +0000
Re: super superclass Christopher Pisz <someone@somewhere.net> - 2012-04-18 16:04 -0500
Re: super superclass Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-04-18 22:07 +0000
Re: super superclass Nobody <nobody@nowhere.com> - 2012-04-19 18:40 +0100
Re: super superclass Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-04-20 07:56 +0000
Re: super superclass Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-04-20 00:29 -0400
| From | bob@coolfone.comze.com |
|---|---|
| Date | 2012-04-17 06:50 -0700 |
| Subject | super superclass |
| Message-ID | <23059116.431.1334670603001.JavaMail.geo-discussion-forums@ynku11> |
In C++, is there a class like the Java Object class that all classes derive from?
[toc] | [next] | [standalone]
| From | Marc <marc.glisse@gmail.com> |
|---|---|
| Date | 2012-04-17 14:29 +0000 |
| Message-ID | <jmjund$idu$1@news-rocq.inria.fr> |
| In reply to | #15427 |
bob@coolfone.comze.com 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.
[toc] | [prev] | [next] | [standalone]
| From | Christopher Pisz <someone@somewhere.net> |
|---|---|
| Date | 2012-04-18 16:04 -0500 |
| Message-ID | <4F8F2C5E.6020904@somewhere.net> |
| In reply to | #15427 |
On 4/17/2012 8:50 AM, bob@coolfone.comze.com 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....
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2012-04-18 22:07 +0000 |
| Message-ID | <slrnjouepj.1ls.grahn+nntp@frailea.sa.invalid> |
| In reply to | #15458 |
On Wed, 2012-04-18, Christopher Pisz wrote: > On 4/17/2012 8:50 AM, bob@coolfone.comze.com 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 .
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2012-04-19 18:40 +0100 |
| Message-ID | <pan.2012.04.19.17.40.30.304000@nowhere.com> |
| In reply to | #15459 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2012-04-20 07:56 +0000 |
| Message-ID | <slrnjp25ls.1ls.grahn+nntp@frailea.sa.invalid> |
| In reply to | #15473 |
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::ostream& operator<< (std::ostream& os, const SomeSuperClass& val)
{
return val.put(os);
}
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> |
|---|---|
| Date | 2012-04-20 00:29 -0400 |
| Message-ID | <4f90e641$0$41637$c3e8da3$3a1a2348@news.astraweb.com> |
| In reply to | #15427 |
bob@coolfone.comze.com 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web