当按下按钮时,wxWidgets项目中的主框架启动了一个线程。我尝试从wxThread类的文档中使用this example,但是在编译时出错。它说

||=== Build: Debug in WindowsDgpsGUI (compiler: GNU GCC Compiler) ===|
D:\WindowsDgpsGui\NavigationThread.cpp||In destructor 'virtual NavigationThread::~NavigationThread()':|
D:\WindowsDgpsGui\NavigationThread.cpp|82|error: 'class wxFrame' has no member named 'm_navigationThreadCS'|
D:\WindowsDgpsGui\NavigationThread.cpp|84|error: 'class wxFrame' has no member named 'm_navigationThread'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

虽然我找不到我做错了什么...
这是我的主要框架的代码:
class WindowsDgpsGUIFrame: public wxFrame
{

    public:

        WindowsDgpsGUIFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~WindowsDgpsGUIFrame();

    protected:
        wxCriticalSection m_navigationThreadCS; //protects the m_navigationThread pointer

        NavigationThread* m_navigationThread;
        friend class NavigationThread;
}

这是线程的 header :
class NavigationThread : public wxThread
{

    public:
        /** \name Constructor */
        NavigationThread(wxFrame* parent, navigation_variables usedVariables);

        /** \name Destructor */
        virtual ~NavigationThread();
    private:
        virtual ExitCode Entry();
        wxFrame* m_parent;
}

这是发生错误的线程的析构函数:
NavigationThread::~NavigationThread()
{
     wxCriticalSectionLocker enter(m_parent->m_navigationThreadCS);

     m_parent->m_navigationThread = NULL;
    //dtor
}

有人知道我做错了吗?任何帮助表示赞赏。

最佳答案

如错误所示:WindowsDgpsGUIFrame类拥有一个成员m_navigationThreadCS。基类wxThread没有。

您正在尝试通过m_navigationThreadCS指针访问wxThread成员变量

NavigationThread::~NavigationThread()
{
     wxCriticalSectionLocker enter(m_parent->m_navigationThreadCS);
                                   ^^^^^^^^

由于m_parent的类型为wxFrame*,因此是您的错误。

您可以dynamic_cast到包含它的派生类中,也可以将m_parent更改为WindowsDgpsGUIFrame*

10-07 15:05