Thread View: comp.std.c++
2 messages
2 total messages
Started by David (Lujun) Shang
Fri, 04 Sep 1992 00:14
What does "::" really mean?
Author: David (Lujun) Shang
Date: Fri, 04 Sep 1992 00:14
Date: Fri, 04 Sep 1992 00:14
39 lines
1882 bytes
1882 bytes
Basically, operator:: does not mean to qualify an identifier. It only
suggests the path to search for the identifier. For example, in expression:
anObject.aClass::aMember
anObject is the qualifier, and aClass suggests that aMember is defined in
aClass or in one of its bases.
A nested class should be a property of its enclosed class, not the property
of its object, therefore we should use expression
aEnclosingClass.aNestedClass
to access the nested class. Mircosoft C/C++7.0 choses to use
aEnclosingClass::aNestedClass
This brings ambiguity. If I have an expression:
C1::C2::C3:: ... ::X
what is the relationship of Ci and Ci-1? The base-derive relationship or
the enclosing-nested relationship? How about when the nested class happened
to be the same name of one of the base classes of its enclosing class?
(consider the fact that the name of a class member can be the same name of
its class or the base class.)
Its rather controversial to argue whether we should use "." or "::" to
access a static member. It depends whether the static member is belong
to the property of the class or the property of the object. To makes
things clear, I would rather to treat static member as the property of
the class, so we should use "." to accress a static member.
If we want to access the class property through an object, we should use
typeof(anObject).aClassProperty
David Shang
Re: What does "::" really mean?
Author: David (Lujun) Shang
Date: Fri, 04 Sep 1992 14:06
Date: Fri, 04 Sep 1992 14:06
48 lines
1374 bytes
1374 bytes
I'd like to add something to my last post on this subject.
Consider an example:
class AA
{ public:
class NAA {};
};
class AA1: public AA
{ public:
class AA
{ public:
class NAA{};
};
};
class AA2: public AA
{ public:
class AA
{ public:
class NAA{};
};
};
class BB: public AA1, public AA2
{
AA1::AA::NAA x; // what is the type of x???
};
What is the type of member "x" in class BB?
We should use:
AA1.AA.NAA
to denote the class NAA nested in class AA nested in class AA1, and use
AA1::AA.NAA
to denote the class NAA nested in the base class AA of AA1.
To conclude, we use"::" to denote a specific base when the member is ambiguous
due to multiple inheritace, and we use "." to denote the member or property of
a qualifying entity ( an object or a class ).
David Shang
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads