struct A {
void foo() {}
};
void bar() {
A a;
a.A::A::A::A::A::A::foo();
}
--
Giovanni Bajo
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
AFAIK, the syntax A::whatever refers to a member of class A. Although
the name A is injected in the scope of A, it's not a member of A, so
writing A::A is illegal. Notice that it doesn't even refer to the class
constructor, because constructors have no name.
That said, applying ::A a second or more times won't improve the
situation, so the answer is definitely no.
Alberto
| Is this code really valid?
|
| struct A {
| void foo() {}
| };
|
| void bar() {
| A a;
| a.A::A::A::A::A::A::foo();
No.
A::A designates the constructor for class A. GCC is defective in not
implementing the rules. I've filled a PR a long time ago.
--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
>Is this code really valid?
>
>struct A {
> void foo() {}
>};
>
>void bar() {
> A a;
> a.A::A::A::A::A::A::foo();
>}
Why shouldn't it be?
--
Bob Hairgrove
NoSpam...@Home.com
However, in the compilers I checked the code with, g++ 3.2, aCC 3.55,
comeau online, it passed. In VC++, it gives a misleading error "error
2039: '__ctor' : is not a member of 'A'"; might be that the vc++
compiler confuses series of A::A as constructors and tries to
interpret it.
-Ganesh
> A::A designates the constructor for class A. GCC is defective in not
> implementing the rules. I've filled a PR a long time ago.
Only in the special case of defining that function. Since the constructors
don't "have names" you can't do
a.A::A()
or even
a.A();
I believe it is valid. See thread
``How to avoid / check typing mistake ":" instead of "::" , with C++ ?''
from April 2004.
Regards,
Vladimir Marko
| Giovanni Bajo wrote:
| > Is this code really valid?
| > struct A {
| > void foo() {}
| > };
| > void bar() {
| > A a;
| > a.A::A::A::A::A::A::foo();
| > }
| >
|
| AFAIK, the syntax A::whatever refers to a member of class A. Although
| the name A is injected in the scope of A, it's not a member of A, so
| writing A::A is illegal.
That is wrong.
A::A is valid. It designates the constructor.
| Notice that it doesn't even refer to the
| class constructor, because constructors have no name.
That is not true. The standard specifically says that it designates
the constructor.
--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
---
| On Mon, 4 Oct 2004 15:16:04 GMT, no...@sorry.com ("Giovanni Bajo")
| wrote:
|
| >Is this code really valid?
| >
| >struct A {
| > void foo() {}
| >};
| >
| >void bar() {
| > A a;
| > a.A::A::A::A::A::A::foo();
| >}
|
| Why shouldn't it be?
Why should it be?
--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
---
Of course I may have been mistaken, but I couldn't find where the
standard says that. Could you enlighten me, please?
Alberto
Yes...the trick is to notice that A::A is not actually a name. A name
is the use of an identifier (3/4) and an identifier may not include
the ":" character. IIRC, A::A is a qualified-id (A.4). And yes, it
designates the ctor.
| "Gabriel Dos Reis" <g...@cs.tamu.edu> wrote in message news:m3sm8tv...@merlin.cs.tamu.edu...
|
| > A::A designates the constructor for class A. GCC is defective in not
| > implementing the rules. I've filled a PR a long time ago.
|
| Only in the special case of defining that function.
No, the meaning of A::A is independent of whether you're defining the
constructor. The meaning is what it is; only the *use* is valid in
context of constructor definition out of class definition.
For example, the following is invalid
A::A a;
Applying you reasoning, it would be valid; alas it is not. See 3.4.3.1.
--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
---
[...]
| > | the name A is injected in the scope of A, it's not a member of A, so
| > | writing A::A is illegal.
| > That is wrong.
| > A::A is valid. It designates the constructor.
| > | Notice that it doesn't even refer to the
| > | class constructor, because constructors have no name.
| > That is not true. The standard specifically says that it designates
| > the constructor.
| >
|
| Of course I may have been mistaken, but I couldn't find where the
| standard says that. Could you enlighten me, please?
If the nested-name-specifier nominates a class C, and the name
specified after the nested-name-specifier, when looked up in C, is
the injected-class-name of C (clause 9), the name is instead
considered to name the constructor of class C. Such a constructor
name shall be used only in the declarator-id of a constructor
definition that appears outside of the class definition. [Example:
struct A { A(); };
struct B: public A { B(); };
A::A() { }
B::B() { }
B::A ba; // object of type A
A::A a; // error A::A is a not a type name
--end example]
So, if a constructor does not have a name, how can "the name is
instead considered to name the constructor"? That is a rhetorical
question :-)
--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
---
| > Is this code really valid?
| > a.A::A::A::A::A::A::foo();
| >From 3.4.5[4], "If the name is found only in the scope of the class of
| the object expression, the name shall refer to a class-name". Since
| the qualifying "class-name-or-namespace-name" is not a class-name, it
| is not valid.
|
| However, in the compilers I checked the code with, g++ 3.2, aCC 3.55,
| comeau online, it passed. In VC++, it gives a misleading error "error
| 2039: '__ctor' : is not a member of 'A'"; might be that the vc++
| compiler confuses series of A::A as constructors and tries to
| interpret it.
I believe VC++ correctly rejects the code because it implements DR
#whatever, that went into the TC1 as 3.4.3.1/1a.
G++ does not implement that rule.
--
Gabriel Dos Reis
g...@cs.tamu.edu
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
---
So what I said wasn't completely wrong as you stated. I wrote "writing
A::A is illegal" and *in that context* (which wasn't "in the
declarator-id of a constructor definition that appears outside of the
class definition") it was in fact illegal. ;-)
> So, if a constructor does not have a name, how can "the name is
> instead considered to name the constructor"? That is a rhetorical
> question :-)
:-D
Alberto
> So, if a constructor does not have a name, how can "the name is
> instead considered to name the constructor"? That is a rhetorical
> question :-)
Not so rhetorical. To name has several meanings in English. One of
them is to designate, which doesn't imply that what is designated
actually has a name. (The example in the American Heritage Dictionary
is "to name the time for our meeting" -- certainly the time named
doesn't have a name.) That would seem to be the meaning here.
Otherwise, why the "instead", which suggests that the name actually
names something else (perhaps the injected class name).
--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34