For example a declaration such as that:
int (x) = 0;
Or even that:
int (((x))) = 0;
I stumbled upon this because in my code I happened to have a fragment similar to the following one:
struct B
{
};
struct C
{
C (B *) {}
void f () {};
};
int main()
{
B *y;
C (y);
}
Obviously I wanted to construct object C
which then would do something useful in its destructor. However as it happens compiler treats C (y);
as a declaration of variable y
with type C
and thus it prints an error about y
redefinition. Interesting thing is that if I write it as C (y).f ()
or as something like C (static_cast<B*> (y))
it will compile as intended. The best modern workaround is to use {}
in constructor call, of course.
So as I figured out after that, it's possible to declare variables like int (x) = 0;
or even int (((x))) = 0;
but I've never seen anyone actually using declarations like this. So I'm interested -what's the purpose of such possibility because for now I see that it only creates the case similar to the notorious "most vexing parse" and doesn't add anything useful?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…