Class prototype

Hello,

I am having some trouble with class prototypes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

using namespace std;

int main()
{
    class Game;   //Prototype declaration
    Game object;
}

class Game   // And the class
{
    public:

        Game() { } ;
       ~Game() { } ;
};


This gives the error:
aggregate 'main()::Game object' has incomplete type and cannot be defined|

It works fine if I declare the class before the main function, and don't use any prototype.
Where is the problem?

Edit:
I just found out what the problem was. I'm not allowed to use a forward declaration to create an object.
I should have found this by searching, but I wasn't aware that prototypes for classes are called forward declarations.
Last edited on
Topic archived. No new replies allowed.