question...
Aziz K.
aziz.kerim at gmail.com
Wed Jan 9 09:52:10 PST 2008
Hi,
Aarti_pl wrote:
> Few minutes ago I recall my previous post here. The problem was that I
> tried to use:
>
> new (int*);
>
> Compiler rejected this style of creating type. But I found out that this
> works properly:
It doesn't work because it's a syntax error according to the D grammar.
After "new" a "Type" is expected which never starts with an opening
parenthesis.
>
> ----------------------------------
>
> Above is ok. for me currently, but I have different problem:
>
> void main() {
> class A {}
> static assert(is( typeof(new A) == typeof(A)) ); // 1
> static assert(is( typeof(new int*) == typeof(int*) )); // 2
> }
>
> First assert compiles, but the second one not.
The second one doesn't compile because it isn't syntactically correct.
The error lies in "typeof(int*)". You are feeding the typeof expression
with a "Type" ("int*"), but it expects an "Expression" (like "int.max",
"new A", "2+5i" etc.) The purpose of typeof is to evaluate (without
side-effects) the expression contained in it and return the type of that.
Regards,
Aziz
More information about the Digitalmars-d-learn
mailing list