Just to make it clear what is happening. Look at this example
int main() { float a = 0; { int(a);
What will come out? Well, it will print 0 . int(a) above can be parsed in two different ways:
- Paste into int and discard result
- Declare a variable named
a . But ignore the parentheses around the identifier.
The compiler, when a situation arises when an expression using a function type expression is used in an expression, and it also looks like an declaration, it will always be perceived as an announcement. When it cannot be syntactically a declaration (the compiler will examine the entire string to determine this), it will be considered an expression. Thus, we assign the inner a above, leaving the outer a equal to zero.
Now that’s your case. You are trying (accidentally) to declare an identifier called a in a class named X :
X (X::A);
Then the compiler continues to moan about the undeclared default constructor, because the static, as it assumes, is constructed by default. But even if you had a default constructor for X, it is of course still erroneous, because none of a is a static member of X, and the staticness of X can be defined / declared in the block area.
You can make this look like an ad by following a few steps. First, you can break up the whole expression, making it no longer look like an ad. Or just undo the type that is superimposed. Both of these ambiguities were mentioned in other answers:
(X(X::A)); (X)(X::A)
When trying to actually declare an object, there is a similar but clear ambiguity. Take a look at this example:
int main() { float a = 0; int b(int(a));
Since int(a) can be either a declaration of a parameter named a or an explicit conversion (cast) of a variable float to int, the compiler again decides that it is a declaration. So we declare a function called b that takes an integer argument and returns an integer. There are several possibilities to eliminate this, based on the values indicated above:
int b((int(a))); int b((int)a);