C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Why is object::type not allowed?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Terje Sletteb?
Guest





PostPosted: Thu Jul 15, 2004 1:57 am    Post subject: Why is object::type not allowed? Reply with quote



Hi.

Consider the following example:

struct test_class
{
typedef int type;

static void f() {}
};

int main()
{
test_class test;

test_class::f(); // Ok
test::f(); // Also ok, type deduced from object

test_class::type i; // Ok
test::type j; // Not ok, error
}

My question is: Why isn't the last example allowed? You can access
static members through an object, but not nested types, which are just
as "static". Does anyone know the reason for this "restriction"? Has
it been considered?

The reason I came to think of it, was the thread "implement a
"for_all" function" in comp.lang.c++
([url]http://groups.google.com/groups?selm=869c2c23.0407121554.51f205ab%40posting.google.com)[/url],
which have this macro:

#define for_all(container) for(container##_type::iterator
itor = container.begin(),
end = container.end();
itor != end;++itor)

If "container::iterator" was legal, there would have been no need for
typeof, or a typedef before the macro use.

Regards,

Terje

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
Terje Sletteb?
Guest





PostPosted: Fri Jul 16, 2004 1:03 am    Post subject: Re: Why is object::type not allowed? Reply with quote



[email]tslettebo (AT) hotmail (DOT) com[/email] (Terje Sletteb?) wrote in message news:<b0491891.0407141326.9033073 (AT) posting (DOT) google.com>...
Quote:
Hi.

Consider the following example:

struct test_class
{
typedef int type;

static void f() {}
};

int main()
{
test_class test;

test_class::f(); // Ok
test::f(); // Also ok, type deduced from object

Sorry, this should be:

test.f(); // Also ok, type deduced from object

This might mean that one can't argue that test::type should be a
natural complement (as it uses "::" rather than "."), but could it
still be useful, such as the macro example in the posting?

Regards,

Terje

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.