super superclass

Discussion in 'C++' started by bob@coolfone.comze.com, Apr 17, 2012.

  1. Guest

    In C++, is there a class like the Java Object class that all classes derive from?
    , Apr 17, 2012
    #1
    1. Advertising

  2. Marc Guest

    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.
    Marc, Apr 17, 2012
    #2
    1. Advertising

  3. On 4/17/2012 8:50 AM, 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....
    Christopher Pisz, Apr 18, 2012
    #3
  4. Jorgen Grahn Guest

    On Wed, 2012-04-18, Christopher Pisz wrote:
    > On 4/17/2012 8:50 AM, 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 .
    Jorgen Grahn, Apr 18, 2012
    #4
  5. Nobody Guest

    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.
    Nobody, Apr 19, 2012
    #5
  6. Pavel Guest

    Pavel, Apr 20, 2012
    #6
  7. Jorgen Grahn Guest

    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::eek:stream& operator<< (std::eek:stream& os, const SomeSuperClass& val)
    {
    return val.put(os);
    }

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, Apr 20, 2012
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    super.super.super how?

    Guest, Feb 19, 2005, in forum: Java
    Replies:
    24
    Views:
    10,744
    Darryl Pierce
    Feb 24, 2005
  2. chriss
    Replies:
    3
    Views:
    459
    chriss
    Sep 10, 2005
  3. Evan Klitzke
    Replies:
    0
    Views:
    348
    Evan Klitzke
    Aug 2, 2007
  4. Ben Finney

    super() doesn't get superclass

    Ben Finney, Sep 18, 2007, in forum: Python
    Replies:
    53
    Views:
    1,301
    OKB (not okblacke)
    Sep 20, 2007
  5. bart van deenen
    Replies:
    6
    Views:
    737
    bart van deenen
    Mar 3, 2009
Loading...

Share This Page