C ++标题问题

时间:2010-10-06 14:26:03

标签: c++ visual-studio-2010

所以我基本上有以下代码。我有工作代码,并希望将其中的一些代码分为两个不同的类D3DWindowD3DController,而不是将它们全部放在D3DWindow中。我不相信它是一个pch问题,因为它在分离之前工作。问题出现在D3DController.cpp中。它说的是D3DController::Create(D3DWindow*) does not match type D3DController::Create(<error-type>*)的所有内容。所有文件都在VS2010中,它们都包含在同一个项目中。对我来说,没有什么能立刻成为问题。

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;
}

1 个答案:

答案 0 :(得分:2)

你有一个循环依赖。也许您可以使用类前向声明​​而不是#include。例如:

// #include "D3DWindow.h"

class D3DWindow; // forward declaration

class D3DController{
    public bool Create(D3DWindow* window);
};