By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,385 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

new class T

P: n/a
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("Hello"));

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("Hello")) not
Gtk::manage(new class Gtk::Label("Hello")). 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

Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Bluear" wrote:
Gtk::Label *label = Gtk::manage(new class Gtk::Label("Hello"));

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("Hello")) not
Gtk::manage(new class Gtk::Label("Hello")). 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!


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
Jul 19 '05 #2

P: n/a
Patrick Frankenberger wrote in news:bh*************@news.t-online.com:

"Bluear" wrote:
Gtk::Label *label = Gtk::manage(new class Gtk::Label("Hello"));
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'
}

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("Hello"))
not Gtk::manage(new class Gtk::Label("Hello")). 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!
In this context class is a synonym for typename if i am not mistaken.


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

template <class Parm1, typename Param2> ...

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".
It would be typename, but in this case I belive Gtk is a namespace
identifier,

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


Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #3

P: n/a
Patrick Frankenberger wrote in news:bh*************@news.t-online.com:

"Bluear" wrote:
Gtk::Label *label = Gtk::manage(new class Gtk::Label("Hello"));
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'
}

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("Hello"))
not Gtk::manage(new class Gtk::Label("Hello")). 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!
In this context class is a synonym for typename if i am not mistaken.


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

template <class Parm1, typename Param2> ...

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".
It would be typename, but in this case I belive Gtk is a namespace
identifier,

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


Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.