A
Allen
In our project, there is a strange problem. Please see the following
codes.
////////////////////////////////////////////////////////////////////////
/// SSControl.h
#pragma pack(1)
typedef struct {
...
} Origin;
typedef struct {
...
} OPER_RESULT;
typedef struct {
...
} OPER_CTRL;
#pragma pack()
class CControl
{
public:
CControl();
~CControl(){};
// member function declarations
......
private:
char appMsgBuf[10240];
char szMTreeBuf[4096];
char ctlRef[256];
char ctlRefFC[256];
// some other member variables
CMTree tree;
......
};
////////////////////////////////////////////////////////////////////////////////
/// SSControl.cpp
CControl::CControl(): tree((unsigned char *)szMTreeBuf,
SSCONTROL_BUF_SIZE)
{
}
// some other member function implementations
As the codes, the CMTree object tree cannot be used as if it was not
initialized to
assign the buffer szMTreeBuf. Then I declare char appMsgBuf[10240],
char szMTreeBuf[4096], char ctlRef[256], char ctlRefFC[256] to be
static, it does work!
And in another CServices class delaration and implementation, it is the
same as
class CControl except #pragam pack (1) struct definitions.
Why does class CControl have to declare static buffers?
codes.
////////////////////////////////////////////////////////////////////////
/// SSControl.h
#pragma pack(1)
typedef struct {
...
} Origin;
typedef struct {
...
} OPER_RESULT;
typedef struct {
...
} OPER_CTRL;
#pragma pack()
class CControl
{
public:
CControl();
~CControl(){};
// member function declarations
......
private:
char appMsgBuf[10240];
char szMTreeBuf[4096];
char ctlRef[256];
char ctlRefFC[256];
// some other member variables
CMTree tree;
......
};
////////////////////////////////////////////////////////////////////////////////
/// SSControl.cpp
CControl::CControl(): tree((unsigned char *)szMTreeBuf,
SSCONTROL_BUF_SIZE)
{
}
// some other member function implementations
As the codes, the CMTree object tree cannot be used as if it was not
initialized to
assign the buffer szMTreeBuf. Then I declare char appMsgBuf[10240],
char szMTreeBuf[4096], char ctlRef[256], char ctlRefFC[256] to be
static, it does work!
And in another CServices class delaration and implementation, it is the
same as
class CControl except #pragam pack (1) struct definitions.
Why does class CControl have to declare static buffers?