gpt4 book ai didi

c++ - 成员函数指针数组 : Getting 0xcccccccc when control reached pointer to member function

转载 作者:搜寻专家 更新时间:2023-10-31 01:23:37 25 4
gpt4 key购买 nike

执行以下代码时出现访问冲突错误:

void NoAction()  
{
(*m_psStateMachine[0][0])();
}
class CXcp
{
public:
CXcp(){}
CXcp(WORD wXcpProtocol);
~CXcp();

private:
void (*m_psStateMachine[10][16])();

public:
// Action Methods from State M/c Table in the RFC//
void IrcScr_6(){}
void IrcStr_4(){}
void TldIrcStr_4(){}
void Tls_1(){}
void Tld_1(){}
void Tlf_0(){}
void Tld(){}
void Str_4(){}
void Str_5(){}
void Scr_6(){}
void Scr_8(){}
void Tlf_2(){}
void Tlf_3(){}
void Tlf_3p(){}
void Sta_2(){}
void IrcScrSca_8(){}
void Sca_8(){}
void ScaTlu_9(){}
void TldScrSca_8(){}
void Scn_6(){}
void Scn_7(){}
void TldScrScn_6(){}
void IrcScrScn_8(){}
void Irc_7(){}
void Scr_6x(){}
void IrcTlu_9(){}
void TldScr_6x(){}
void Sta_3(){}
void IrcScr_8(){}
void Sta_4(){}
void Sta_5(){}
void Sta_6(){}
void TldZrcSta_6(){}
void TldScr_6(){}
void Scj_2(){}
void Scj_3(){}
void Scj_4(){}
void Scj_5(){}
void Scj_6(){}
void Scj_7(){}
void Scj_8(){}
void Scj_9(){}
void TldIrcStr_5(){}
void Ser_9(){}

void NoAction()
{
(*m_psStateMachine[0][0])();
}
void Initial() {}
void Starting() {}
void Closed() {}
void Stopped() {}
void Closing() {}
void Stopping() {}
void ReqSent() {}
void AckRecvd() {}
void AckSent() {}
void Opened() {}
};

CXcp::CXcp(WORD wXcpProtocol)
{


// Kernel of the PPP the State M/c : Initialization Here
void (CXcp :: *m_psStateMachine[10][16])() =
{
/* State
0 1 2 3 4 5 6 7 8 9
Events | INITIAL STARTING CLOSED STOPPED CLOSING STOPPING Req-Sent Ack-Rcvd Ack-Sent OPENED */

/*Up*/ &CXcp::Initial, &CXcp::IrcScr_6, &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction,

/*Down*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Initial, &CXcp::Tls_1, &CXcp::Initial, &CXcp::Starting, &CXcp::Starting, &CXcp::Starting, &CXcp::Starting, &CXcp::Tld_1,

/*Open*/ &CXcp::Tls_1, &CXcp::Starting, &CXcp::IrcScr_6, &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction, &CXcp::ReqSent, &CXcp::AckRecvd, &CXcp::AckSent, &CXcp::Opened,

/*Close*/ &CXcp::Initial, &CXcp::Tlf_0, &CXcp::Closed, &CXcp::Closed, &CXcp::Closing, &CXcp::Closing, &CXcp::IrcStr_4, &CXcp::IrcStr_4, &CXcp::IrcStr_4, &CXcp::TldIrcStr_4,

/*TO+*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction, &CXcp::Str_4, &CXcp::Str_5, &CXcp::Scr_6, &CXcp::Scr_6, &CXcp::Scr_8, &CXcp::NoAction,

/*TO-*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction, &CXcp::NoAction, &CXcp::Tlf_2, &CXcp::Tlf_3, &CXcp::Tlf_3p, &CXcp::Tlf_3p, &CXcp::Tlf_3p, &CXcp::NoAction,

/*RCR+*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Sta_2, &CXcp::IrcScrSca_8, &CXcp::Closing, &CXcp::Stopping, &CXcp::Sca_8, &CXcp::ScaTlu_9, &CXcp::Sca_8, &CXcp::TldScrSca_8,

/*RCR-*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Sta_2, &CXcp::IrcScrSca_8, &CXcp::Closing, &CXcp::Stopping, &CXcp::Scn_6, &CXcp::Scn_7, &CXcp::Scn_6, &CXcp::TldScrScn_6,

/*RCA*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Sta_2, &CXcp::IrcScrScn_8, &CXcp::Closing, &CXcp::Stopping, &CXcp::Irc_7, &CXcp::Scr_6x, &CXcp::IrcTlu_9, &CXcp::TldScr_6x,

/*RCN*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Sta_2, &CXcp::Sta_3, &CXcp::Closing, &CXcp::Stopping, &CXcp::IrcScr_6, &CXcp::Scr_6x, &CXcp::IrcScr_8, &CXcp::TldScr_6x,

/*RTR*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Sta_2, &CXcp::Sta_3, &CXcp::Sta_4, &CXcp::Sta_5, &CXcp::Sta_6, &CXcp::Sta_6, &CXcp::Sta_6, &CXcp::TldZrcSta_6,

/*RTA*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Closed, &CXcp::Stopped, &CXcp::Tlf_2, &CXcp::Tlf_3, &CXcp::ReqSent, &CXcp::ReqSent, &CXcp::AckSent, &CXcp::TldScr_6,

/*RUC*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Scj_2, &CXcp::Scj_3, &CXcp::Scj_4, &CXcp::Scj_5, &CXcp::Scj_6, &CXcp::Scj_7, &CXcp::Scj_8, &CXcp::Scj_9,

/*RXJ+*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Closed, &CXcp::Stopped, &CXcp::Closing, &CXcp::Stopping, &CXcp::ReqSent, &CXcp::ReqSent, &CXcp::AckSent, &CXcp::Opened,

/*RXJ-*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Tlf_2, &CXcp::Tlf_3, &CXcp::Tlf_2, &CXcp::Tlf_3, &CXcp::Tlf_3, &CXcp::Tlf_3, &CXcp::Tlf_3, &CXcp::TldIrcStr_5,

/*RXR*/ &CXcp::NoAction, &CXcp::NoAction, &CXcp::Closed, &CXcp::Stopped, &CXcp::Closing, &CXcp::Stopping, &CXcp::ReqSent, &CXcp::AckRecvd, &CXcp::AckSent, &CXcp::Ser_9

};
}

CXcp::~CXcp()
{

}

int main(void)
{
CXcp oXcp(10);
oXcp.NoAction();
return 0;
}

回答将不胜感激。

提前致谢

最佳答案

好吧,你没有初始化这个成员:

void (*m_psStateMachine[10][16])();

您要做的是在构造函数中创建一个本地数组,并初始化那个。那只能失败。把成员改成这个

void (CXcp::*m_psStateMachine[10][16])();

然后在构造函数中,将本地数组复制到成员中(最好从本地数组名称中删除 m_ 前缀,以免与实际成员数组混淆)。

for(int i = 0; i < 10; i++)
for(int j = 0; j < 16; j++)
this->m_psStateMachine[i][j] = stateMachine[i][j];

或者,你可以单独分配每个元素,如果你喜欢巨大的痛苦:) 然后你使用另一种语法调用成员指针数组

(this->*m_psStateMachine[0][0])();

当然,某处您需要告诉它在哪个对象上调用它。

关于c++ - 成员函数指针数组 : Getting 0xcccccccc when control reached pointer to member function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1092147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com