1

The class called Universes uses a data member of type States, whilst States uses an object of type Universes. I'm using Visual C++ 2010 Express (if that makes any difference).

States.h:

class Universes;

extern Universes universe;

class States
{
public:

    int relations;

    States();
};

States::States()
{
    relations = universe.state_no;
}

Universes.h

#include "States.h"

class Universes
{
public:
    States state;
    int state_no;
};

Test.cpp

#include "stdafx.h"
#include <iostream>
#include <conio.h>

#include "Universes.h"

using namespace System;

int main(array<System::String ^> ^args)
{
    Universes universe;
    _getch();
    return 0;
}

I keep getting the following errors:

States.h(16): error C2027: use of undefined type 'Universes'
States.h(1) : see declaration of 'Universes'
States.h(16): error C2228: left of '.state_no' must have class/struct/union
  • possible duplicate of [Header files inclusion / Forward declaration](http://stackoverflow.com/questions/2832714/header-files-inclusion-forward-declaration) – SomeWittyUsername Mar 02 '13 at 17:27

1 Answers1

0

At the point where you try to access universe.state_no, the Universes class is incomplete (it's forward-declared).

A clean way to fix this is to move the definition of States::States into States.cpp, and make sure States.cpp #includes Universes.h.

NPE
  • 486,780
  • 108
  • 951
  • 1,012