new class T

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bluear

    #1

    new class T

    Since I failed to find an answer in various FAQs and groups I hope
    somebody can help me out here. Also, if this is a FAQ my apologies. After
    this introduction, here it goes:

    I noticed that glade (http://glade.gnome.org/) when generating code in C++
    creates code like the one presented below:

    Gtk::Label *label = Gtk::manage(new class Gtk::Label("Hel lo"));

    Gtk::manage() provides for automatic management of dynamically allocated
    widgets. Now the question I have is about *new class*. In the Gtkmm
    documentation I see Gtk::manage(new Gtk::Label("Hel lo")) not
    Gtk::manage(new class Gtk::Label("Hel lo")). Yet my compiler (gcc 3.2.3)
    gladly accept this. So what is the meaning of "new class T"? How does it
    differ from "new T"? Pointers to books, technical reports and such
    explaining the above are greatly appreciated!

    --
    delete fubar to e-mail me

  • Patrick Frankenberger

    #2
    Re: new class T


    "Bluear" wrote:[color=blue]
    > Gtk::Label *label = Gtk::manage(new class Gtk::Label("Hel lo"));
    >
    > Gtk::manage() provides for automatic management of dynamically allocated
    > widgets. Now the question I have is about *new class*. In the Gtkmm
    > documentation I see Gtk::manage(new Gtk::Label("Hel lo")) not
    > Gtk::manage(new class Gtk::Label("Hel lo")). Yet my compiler (gcc 3.2.3)
    > gladly accept this. So what is the meaning of "new class T"? How does it
    > differ from "new T"? Pointers to books, technical reports and such
    > explaining the above are greatly appreciated![/color]

    In this context class is a synonym for typename if i am not mistaken.

    If T is not a member of a template parameter "new T" is exactly the same as
    "new class T". If T is a member of a template parameter you need to add
    "class" or "typename".

    template<class X> void* x()
    {
    return new class X::value_type;
    }

    HTH,
    Patrick


    Comment

    • Rob Williscroft

      #3
      Re: new class T

      Patrick Frankenberger wrote in news:bh3ra9$ecf $01$1@news.t-online.com:
      [color=blue]
      >
      > "Bluear" wrote:[color=green]
      >> Gtk::Label *label = Gtk::manage(new class Gtk::Label("Hel lo"));[/color][/color]

      This isn't a particularly good example, how about:

      class A {};

      int main()
      {
      int A; // local variable 'A' hides the class name 'A'

      class A a; // OK - got passed the name hiding by using 'class'
      }
      [color=blue][color=green]
      >>
      >> Gtk::manage() provides for automatic management of dynamically
      >> allocated widgets. Now the question I have is about *new class*. In
      >> the Gtkmm documentation I see Gtk::manage(new Gtk::Label("Hel lo"))
      >> not Gtk::manage(new class Gtk::Label("Hel lo")). Yet my compiler (gcc
      >> 3.2.3) gladly accept this. So what is the meaning of "new class T"?
      >> How does it differ from "new T"? Pointers to books, technical reports
      >> and such explaining the above are greatly appreciated![/color]
      >
      > In this context class is a synonym for typename if i am not mistaken.[/color]

      class isn't a synonym for typename, the only situation in which they
      are equivalent is:

      template <class Parm1, typename Param2> ...
      [color=blue]
      >
      > If T is not a member of a template parameter "new T" is exactly the
      > same as "new class T". If T is a member of a template parameter you
      > need to add "class" or "typename".[/color]

      It would be typename, but in this case I belive Gtk is a namespace
      identifier,
      [color=blue]
      >
      > template<class X> void* x()
      > {
      > return new class X::value_type;[/color]
      return new typename X::value_type;
      [color=blue]
      > }
      >[/color]

      Rob.
      --

      Comment

      • Rob Williscroft

        #4
        Re: new class T

        Patrick Frankenberger wrote in news:bh3ra9$ecf $01$1@news.t-online.com:
        [color=blue]
        >
        > "Bluear" wrote:[color=green]
        >> Gtk::Label *label = Gtk::manage(new class Gtk::Label("Hel lo"));[/color][/color]

        This isn't a particularly good example, how about:

        class A {};

        int main()
        {
        int A; // local variable 'A' hides the class name 'A'

        class A a; // OK - got passed the name hiding by using 'class'
        }
        [color=blue][color=green]
        >>
        >> Gtk::manage() provides for automatic management of dynamically
        >> allocated widgets. Now the question I have is about *new class*. In
        >> the Gtkmm documentation I see Gtk::manage(new Gtk::Label("Hel lo"))
        >> not Gtk::manage(new class Gtk::Label("Hel lo")). Yet my compiler (gcc
        >> 3.2.3) gladly accept this. So what is the meaning of "new class T"?
        >> How does it differ from "new T"? Pointers to books, technical reports
        >> and such explaining the above are greatly appreciated![/color]
        >
        > In this context class is a synonym for typename if i am not mistaken.[/color]

        class isn't a synonym for typename, the only situation in which they
        are equivalent is:

        template <class Parm1, typename Param2> ...
        [color=blue]
        >
        > If T is not a member of a template parameter "new T" is exactly the
        > same as "new class T". If T is a member of a template parameter you
        > need to add "class" or "typename".[/color]

        It would be typename, but in this case I belive Gtk is a namespace
        identifier,
        [color=blue]
        >
        > template<class X> void* x()
        > {
        > return new class X::value_type;[/color]
        return new typename X::value_type;
        [color=blue]
        > }
        >[/color]

        Rob.
        --

        Comment

        Working...