This is abuse of the term "prototype".
A class is a "type".
Your forward declaration in line 5 just tells us the type exists, not how to create it.
At line 10, you're trying to create an object. At this point, the type of the object is not known so it cannot be created.
For example, we don't know the size (do we have to make some space for it on the stack)? Base classes to be initialised? Member objects? Memory allocated on heap? In short, we need to call the constructor, as implied by the name, to construct the object.
To put it in (very) crude terms, as you pointed out, you can prototype a function and call it before the definition is seen, but you can't use it before the prototype (declaration) is seen. The same thing is true here - we need to have seen the "constructor prototype", before we can create the object.
Look at it this way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
using namespace std;
class Foo
{
public:
Foo();
};
int main()
{
Foo bar;
return 0;
}
Foo::Foo()
{
cout << "constructor created" << endl;
}
|