Re: new foo::foo() erroneous, ugly, or OK?
In article <FPmdnWQu2fehsgLZnZ2dnUVZ_v-dnZ2d@comcast.com>, Victor
Bazarov <v.Abazarov@comAcast.net> writes
foo *myfoo = new foo::foo();
foo.cpp 8 Error 1018: Expected a type after 'new'
[...]
I'm not a C++ expert, so my question to the resident AI is:
Is this in fact an error, or does the C++ standard
allow this syntactically/semantically?
It is perfectly fine. 'foo' _class_ owns the name 'foo' as its
own type. 'foo::foo' is just as good as a *type-id* as, for
example 'foo::foo::foo::foo::foo::foo'. There should be no error
report. FlexeLint is buggy (as much as they love touting their
own horn, thier software is written by people too).
Well Flexelint is usually pretty good and it seems unlikely that it is
mistaken so I tried this code;
struct foo {
foo();
};
int main (){
foo * f = new foo::foo();
}
In Comeau in strict mode and got
"ComeauTest.c", line 7: error: expected a type specifier
foo * f = new foo::foo();
^
1 error detected in the compilation of "ComeauTest.c".
It gave the same response when compiling in relaxed mode which leads me
to think that Flexelint is, in fact, right.
This is a rather language lawerish issue but why would anyone want to
write foo::foo() instead of foo()?
--
Francis Glassborow ACCU
Author of 'You Can Do It!' and "You Can Program in C++"
see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/
youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]