Deleted constructor acts strangely

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
Consider the line
Foo a1();
This is a function declaration.
Last edited on
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!
I understood finally. Didn't know I could declare a function inside another function!
Topic archived. No new replies allowed.