Jul 31, 2020 at 6:49am UTC  
 
I have the following class:
1 2 3 4 5 6 7 8 9 
class  Foo
{
public :
	int  blablabla;
	Foo() = delete ;
	Foo(int  x) : blablabla(x) {};
	~Foo() {};
};
 
As you see, I have deleted the default constructor. But I noticed something strange:
1 2 
Foo a1(); // works! 
Foo a2 = Foo(); // compiler error!  
 
Why am I able to use the constructor that I deleted? And if the first statement is OK, what's wrong with the second one? I thought they are equivalent. 
 
Last edited on Jul 31, 2020 at 6:51am UTC  
 
 
 
 
  Jul 31, 2020 at 6:56am UTC  
 
Consider the line 
Foo a1();  
This is a function declaration.
Last edited on Jul 31, 2020 at 6:56am UTC  
 
 
 
 
  Jul 31, 2020 at 6:59am UTC  
 
Your first line isn't calling a constructor: it's declaring (but not defining) a function that returns a Foo. 
 
See what happens if you remove the (). 
 
No, I dislike it, too!
 
 
 
 
  Jul 31, 2020 at 10:51am UTC  
 
I understood finally. Didn't know I could declare a function inside another function!