I define a wxObjArray in my TMainFrame.h
as follows:
#ifndef __TMainFrame__
#define __TMainFrame__
#include "MyApp_gui.h"
//// end generated include
#include "TRunThread.h"
#include <wx/dynarray.h>
class TMove;
WX_DECLARE_OBJARRAY(TMove, TMoveArray);
/* ...Class TMainFrame... */
/* ...Class TMove... */
#endif // __TMainFrame__
Now I want to use the class TMoveArray created by WX_DECLARE_OBJARRAY in my TRunThread.h
.
But that class cannot be found (GCC: 'TMoveArray' has not been declared)
#ifndef TRUNTHREAD_H_INCLUDED
#define TRUNTHREAD_H_INCLUDED
#include <wx/wx.h&g开发者_如何转开发t;
#include "TMainFrame.h"
// doesn't work: WX_DECLARE_OBJARRAY(TMove, TMoveArray);
class TRunThread : public wxThread
{
public:
wxThreadError Create(TMoveArray moves);
};
#endif // TRUNTHREAD_H_INCLUDED
The source file TRunThread.cpp
:
#include <wx/arrimpl.cpp> // this is a magic incantation which must be done!
WX_DEFINE_OBJARRAY(TMoveArray);
#include "TRunThread.h"
/* ...Code... */
I've also tried with the WX_DEFINE_OBJARRAY
directive.
Question: How to include a wxObjArray correctly?
You are going to need both WX_DECLARE_OBJARRAY
and WX_DEFINE_OBJARRAY
. The latter goes to an implementation file.
The reference has a full usage example and more comments.
And you might also just use std::vector
.
精彩评论