Topic: Is it legal to directly call a constructor?
Author: goodbyeera@gmail.com
Date: Tue, 28 Apr 2009 13:04:23 CST Raw View
class A {
void f() { this->A::A(); }
};
Let's just put away the logic of the program for a moment. I'm just
wondering whether this syntax is legal in standard C++ or not. This
compiles OK in VC and GCC, but fails in Comeau. I'm not able to find
a direct answer to this in the standard. Can anyone help to explain
whether it is syntactically legal? Thank you very much.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "fuyanghan1986@gmail.com" <fuyanghan1986@gmail.com>
Date: Wed, 29 Apr 2009 12:09:59 CST Raw View
On Apr 29, 3:04 am, goodbye...@gmail.com wrote:
> class A {
> void f() { this->A::A(); }
>
> };
>
> Let's just put away the logic of the program for a moment. I'm just
> wondering whether this syntax is legal in standard C++ or not. This
> compiles OK in VC and GCC, but fails in Comeau. I'm not able to find
> a direct answer to this in the standard. Can anyone help to explain
> whether it is syntactically legal? Thank you very much.
>
> --
> [ 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 ]
i dont know why u do that....
oo make sure you must construct a object before call the method
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Steve Clamage <stephen.clamage@sun.com>
Date: Wed, 29 Apr 2009 12:44:20 CST Raw View
On 04/28/09 12:04, goodbyeera@gmail.com wrote:
class A {
void f() { this->A::A(); }
};
Let's just put away the logic of the program for a moment. I'm just
wondering whether this syntax is legal in standard C++ or not. This
compiles OK in VC and GCC, but fails in Comeau. I'm not able to find
a direct answer to this in the standard. Can anyone help to explain
whether it is syntactically legal? Thank you very much.
>From the 2003 C++ Standard:
3.4.3 "Qualified name lookup", paragraph 1:
"The name of a class or namespace member can be referred to after the
:: scope resolution operator applied to a nested-name-specifier that
nominates its class or namespace."
3.4.3.1 "Class members", paragraph 1a:
"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, 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 the
class definition."
The example syntax A::A is not valid.
---
Steve Clamage
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: James Kanze <james.kanze@gmail.com>
Date: Wed, 29 Apr 2009 22:25:37 CST Raw View
On Apr 28, 9:04 pm, goodbye...@gmail.com wrote:
> class A {
> void f() { this->A::A(); }
>
> };
> Let's just put away the logic of the program for a moment.
> I'm just wondering whether this syntax is legal in standard
> C++ or not.
It's not. According to the grammar, -> can be either:
postfix-expression -> template[opt] id-expression
or
postfix-expression -> pseudo-destructor-name
Since A::A() is not a pseudo-destructor-name, it must be the
first, which is described in 5.2.5 Class member access, where
it says "[...] the id-expression shall name a member of the
class or of one of its base classes." And further down:
"[concerning E1.E2]--- If E2 is a nested type, the expression
E1.E2 is ill-formed." Depending on how you interpret class name
injection ( 9/2), either A::A doesn't name a member of the class
(and there are no members of any base classes), or it names a
nested type, so either way, the expression is illegal. (I think
that the standard interpretation is that it names a nested
type. At any rate, it certainly names a type)
> This compiles OK in VC and GCC, but fails in Comeau. I'm not
> able to find a direct answer to this in the standard.
> Can anyone help to explain whether it is syntactically legal?
The rules given in 5.2.5 would seem quite clearly to forbid it.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
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
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: James Hopkin <tasjaevan@gmail.com>
Date: Thu, 30 Apr 2009 12:12:07 CST Raw View
On Apr 28, 8:04 pm, goodbye...@gmail.com wrote:
> class A {
> void f() { this->A::A(); }
>
> };
>
> Let's just put away the logic of the program for a moment. I'm just
> wondering whether this syntax is legal in standard C++ or not. This
> compiles OK in VC and GCC, but fails in Comeau. I'm not able to find
> a direct answer to this in the standard. Can anyone help to explain
> whether it is syntactically legal? Thank you very much.
>
Just a point of information: gcc4.3 doesn't accept it, but VC9 (Visual
Studio 2008) still does.
James
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]