各位好,小题是这样的:
有
对话框类:CMutexesDlg;
CWinThread 的派生类: CExampleThread;
CExampleThread 的派生类: CCounterThread 和 CDisplayThread; 1、想在CExampleThread 的头文件中填加如下变量:
CMutexesDlg * m_pOwner;// 指向类CMutexesDlg指针
及函数:
void SetOwner(CMutexesDlg* pOwner)
{ m_pOwner=pOwner; };// 取类CMutexesDlg的指针 2、想在CMutexesDlg 的头文件中加入如下成员变量:
CCounterThread* m_pCounterThread;
CDisplayThread* m_pDisplayThread;问题是不知如何引用起头文件,请各位指点,谢谢。现经人指点:
直接在头文件中声名CMutexesDlg类的前面加入:
//MutexesDlg.h
...
...
...Class CCounterThread;//需要添加的
Class CDisplayThread;//需要添加的
...
//下面就是CMutexesDlg类的声名
Class CMutexesDlg:public CDialog
{
...
CCounterThread* m_pCounterThread;
CDisplayThread* m_pDisplayThread;...
}定义是可以了,可在引用时
m_pDisplayThread = (CDisplayThread*)AfxBeginThread(RUNTIME_CLASS(CDisplayThread),
THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
m_pDisplayThread->SetOwner(this);出错:
error C2027: use of undefined type 'CDisplayThread'
mutexesdlg.h(16) : see declaration of 'CDisplayThread'请各位指点啊
有
对话框类:CMutexesDlg;
CWinThread 的派生类: CExampleThread;
CExampleThread 的派生类: CCounterThread 和 CDisplayThread; 1、想在CExampleThread 的头文件中填加如下变量:
CMutexesDlg * m_pOwner;// 指向类CMutexesDlg指针
及函数:
void SetOwner(CMutexesDlg* pOwner)
{ m_pOwner=pOwner; };// 取类CMutexesDlg的指针 2、想在CMutexesDlg 的头文件中加入如下成员变量:
CCounterThread* m_pCounterThread;
CDisplayThread* m_pDisplayThread;问题是不知如何引用起头文件,请各位指点,谢谢。现经人指点:
直接在头文件中声名CMutexesDlg类的前面加入:
//MutexesDlg.h
...
...
...Class CCounterThread;//需要添加的
Class CDisplayThread;//需要添加的
...
//下面就是CMutexesDlg类的声名
Class CMutexesDlg:public CDialog
{
...
CCounterThread* m_pCounterThread;
CDisplayThread* m_pDisplayThread;...
}定义是可以了,可在引用时
m_pDisplayThread = (CDisplayThread*)AfxBeginThread(RUNTIME_CLASS(CDisplayThread),
THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
m_pDisplayThread->SetOwner(this);出错:
error C2027: use of undefined type 'CDisplayThread'
mutexesdlg.h(16) : see declaration of 'CDisplayThread'请各位指点啊
引用时你指定了要把AfxBeginThread 的返回值转换为 (CDisplayThread*) 类型
但是编译器只知道CDisplayThread是个类,对它的大小、有哪些成员不清楚
假如编译器允许编译通过,编译器怎么指定类似下面的调用是否合法:
m_pDisplayThread->GetName();所以必须告诉编译器CDisplayThread的定义。解决方法:
假设下面调用:
m_pDisplayThread = (CDisplayThread*)AfxBeginThread(RUNTIME_CLASS(CDisplayThread),
THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
m_pDisplayThread->SetOwner(this);
在文件 MutexesDlg.cpp 中
在最文件开头加入
#include "DisplayThread.h" //DisplayThread.h 包含了类CDisplayThread的声明。注意:
DisplayThread.h 仍然可以包含你的MutexesDlg.h文件。不知道能否解决你的问题。
error C2504: 'CExampleThread' : base class undefined