读书人

一个很诡异的有关问题求大神帮助

发布时间: 2013-09-05 16:02:07 作者: rapoo

一个很诡异的问题,求大神帮助
事情是这样的。
有2个文件:
TestLocalPlayerDlg.h


#pragma once
#include "..."
//... //一些声明
#include "Update.h"

class CTestLocalPlayerDlg
{
public :
void app();
//一些函数
};


Update.h

#pragma once
#include "..."
//一些声明
class CTestLocalPlayerDlg;//前向引用声明
class CUpdate
{
public:
void hello();
};

Update.cpp

#include "stdafx.h"
#include "Update.h"
#include "TestLocalPlayer.h"
//问题来了!!!!!!!!!!!!!!!!!!
void CUpdate::hello()
{
//编译的时候 , 如果没有下面注释掉的那句(pWnd->app() ),这个程序可以编译
//这里单步调试显示pWnd获取到的值没有错误
CTestLocalPlayerDlg* pWnd = (CTestLocalPlayerDlg* )AfxGetApp()->GetMainWnd();
//当我加上pWnd->app(),提示错误,错误如下
/*
error C2027: 使用了未定义类型“CTestLocalPlayerDlg”
参见“CTestLocalPlayerDlg”的声明
error C2227: “->app()”的左边必须指向类/结构/联合/泛型类型
*/
//pWnd->app();

//诡异了 这是为什么? 怎么调??pWnd我确定已经成功转换了,因为单步调试的时候我看到了相应的变量
}

[解决办法]
app() 不是 TestLocalPlayerDlg 的函数
app 与 dlg 不是一个类
[解决办法]
Update.cpp中要#include"TestLocalPlayerDlg.h"
你在Update.h只是前置申明而已
[解决办法]
“class CTestLocalPlayerDlg;//前向引用声明
class CUpdate” 只用到 CTestLocalPlayerDlg* 编译器 不需要 知道
如果 app 是 CTestLocalPlayerDlg 的 函数 ,编译器 就要 知道 CTestLocalPlayerDlg 的 内容
------解决方案--------------------


你看清楚了,你写的是#include "TestLocalPlayer.h"

读书人网 >VC/MFC

热点推荐