recently I found a bug in my program caused by adding extra parentheses.
Following is my code. The program print nothing but "end main"
#include <stdio.h>
class A
{
public:
A()
{
printf("init\n");
}
A(A& a)
{
printf("copy constructor");
}
~A()
{
printf("finit\n");
}
};
int main()
{
A a();
printf("end main\n");
}
But when I remove parentheses in the the main function, it prints "init", "finit" and "end main", this is what I want.
int main()
{
A a;
printf("end main\n");
}
Could anyone tell me why? I compiled the code in VS2013 and gcc4.7.2, the results are same.