 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Terje Sletteb? Guest
|
Posted: Thu Jul 15, 2004 1:57 am Post subject: Why is object::type not allowed? |
|
|
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
|
Posted: Fri Jul 16, 2004 1:03 am Post subject: Re: Why is object::type not allowed? |
|
|
[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 |
|
 |
|
|
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
|
|