views:

61

answers:

1
+2  Q: 

C++ header issue

So I essentially have the following code. I had working code and wanted to separate some of it into two different classes, D3DWindow and D3DController, rather than having it all in D3DWindow. I don't believe it is a pch problem because it was working prior to the separation. The problem occurs in D3DController.cpp. It says something along the lines of D3DController::Create(D3DWindow*) does not match type D3DController::Create(<error-type>*) All of the files are in VS2010 and they are all contained in the same project. Nothing stood out immediately as the issue to me.

stdafx.h

#include <d3d10.h>
#include <windows.h>
#include "D3DWindow.h"
#include "D3DController.h"

stdafx.cpp

#include "stdafx.h"

D3DWindow.h

#include "D3DController.h"
class D3DWindow{
    D3DController controller;
    public bool init();
};

D3DWindow.cpp

#include "stdafx.h"
bool D3DWindow::init(){
    if(!controller.create(this))
        return false;
    return true;
}

D3DController.h

#include "D3DWindow.h"
class D3DController{
    public bool Create(D3DWindow* window);
};

D3DController.cpp

#include "stdafx.h"
bool D3DController::Create(D3DWindow* window){
    // Do Stuff
    return true;
}
+2  A: 

You have a circular dependency. Perhaps you can use a class forward declaration instead of #include. E.g.:

// #include "D3DWindow.h"

class D3DWindow; // forward declaration

class D3DController{
    public bool Create(D3DWindow* window);
};
ur
Cool, I'll give this a shot. Are there any nuances to the forward declarations?
Kyle
From your code snippet: The header file for D3Dcontroller doesn't use/reference the class D3DWindow but only a pointer to D3DWindow. You can think of "the compiler doesn't have to know the byte size of a D3DWindow or it's members here". Don't forget to include "D3DWindow.h" in "D3DController.cpp" or you might get another compilation error ("you are using an undefined type" or something). No caveats.
ur