0

When I try to compile my following code , I receive an error that Test does not name a type. How is this possible as I seem to have included the header files correctly? Thanks in advance.

//Test.h
#include "Test2.h"

class Test
{
    Test2 t2;
};

//Test2.h
#include "Test.h"

class Test2
{
    Test t;
};

//main.cpp
#include "Test.h"

int main()
{
}
Mat
  • 202,337
  • 40
  • 393
  • 406
Engineer999
  • 3,683
  • 6
  • 33
  • 71
  • The third tag pretty much answers your question (http://en.cppreference.com/w/cpp/language/class#Forward_declaration). – Floris Velleman May 12 '15 at 15:45
  • Research the internet for "c++ include guards". – Thomas Matthews May 12 '15 at 15:46
  • Why would I search the internet for c++ include guards? What has that got to do with this problem? They are removed especially here for simplicity of including less code in the question and showing the main issue. – Engineer999 May 12 '15 at 16:02
  • @Engineer999: Don't get tetchy -- people here are trying to help you! Removing those include guards has changed your problem from a finite one to an infinite one. Put them back in (after you have worked out why they are essential here). – TonyK May 12 '15 at 18:32
  • I know people are trying to help and thanks. It's just the way it was put. I understand the purpose of include guards and it would cause an infinite problem here without them so I should have left them in. I'm fairly new to C++ so I'm just trying to understand how the compiler works. – Engineer999 May 14 '15 at 09:39

0 Answers0