Topic: Why is object::type not allowed?
Author: tslettebo@hotmail.com (Terje Sletteb?)
Date: Thu, 15 Jul 2004 01:57:36 +0000 (UTC) Raw View
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++
(http://groups.google.com/groups?selm=869c2c23.0407121554.51f205ab%40posting.google.com),
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 ]
Author: tslettebo@hotmail.com (Terje Sletteb?)
Date: Fri, 16 Jul 2004 01:03:44 +0000 (UTC) Raw View
tslettebo@hotmail.com (Terje Sletteb?) wrote in message news:<b0491891.0407141326.9033073@posting.google.com>...
> 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 ]