0

i made class 'Object' and 'Vector', in the each header file. ('Object' is parent class of 'Vector') and made 'Engine.h' header file that include both class header file.

build was successful. but, if i create 'Object.cpp' file which is empty got error. like this 'Vector.h(7,2): error C2504: 'Object': base class undefined'

could you tell me why 'Object.cpp' file occurs this error?

//Engine.h
#pragma once
#include "Object.h"
#include "Vector.h"

namespace Engine
{

}

//Object.h
#pragma once
#include "Engine.h"

namespace Engine
{
    class Object
    {

    };
}

//Vector.h
#pragma once
#include "Engine.h"

namespace Engine
{
    class Vector : public Object
    {

    };
}
#include <iostream>
#include "Engine.h"

int main()
{
    return 0;
}
ghoflvhxj
  • 1
  • 3

1 Answers1

2

You've forgotten to #include "Object.h" in your Vector.h file.

It also looks like a lot of your classes rely on one another - that's a bit of a code smell, and it's resulting in compiler errors since you've got circular include statements. If Engine includes Object and Object includes Engine, you can't compile - one of them is always going to be undefined.

Nick Reed
  • 4,989
  • 4
  • 17
  • 37