void g()
{
// How can we access type Container::X here, since we cannot use
typename in normal class?
}
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
> class Container
> {
> public:
> static int X;
> class X
...
>
> How can we access type Container::X here, since we cannot use
> typename in normal class?
You can use "class Container::X", e.g.:
void g()
{
Container c;
class Container::X x;
c.X = 3;
}
-Miles
--
Inhumanity, n. One of the signal and characteristic qualities of humanity.
Same as for similar case with namespace scope:
class C::X foo; // C::X is type here
int n = C::X; // C::X is static member here
Note that this won't compile in the first place:
class C {
static int X;
typedef int X;
};
so there's no issue with disambiguation in that case (where you
couldn't use class/struct/union tag).
You are only allowed to use the name X for both the variable and the
class due to a backwards compatibility rule with C where the struct
names live in a different namespace to other names.
In other words what you have is equivalent to the following:
int X;
struct X;
The rule in this case is that the struct name is hidden. You can
explicitly refer to it with struct X or class X; in your case class
Container::X. And as a general rule, don't do that.
Yechezkel Mett