c++ - Access Violation with no apparent nullptr -


i writing mfc application , have created derived class cstatusbarpane publicly derives cmfcribbonstatuspane. derived class contains simple method follows:

virtual void setstatusicon( _in_ hicon hicon ) {      m_hiconsmall = hicon;      redraw(); } 

after main frame created (along status bar , children panes), call following function:

void cmainframe::updatestatusbar( _in_ const std::tstring& szstatus, _in_opt_ hicon hicon ) {      cstatusbarpane* pstatusbarpane = static_cast<cstatusbarpane*>(m_wndstatusbar.getelement(0));       pstatusbarpane->settext( szstatus.c_str() );      pstatusbarpane->setstatusicon( hicon ); } 

however, when debug application, raises exception on line pstatusbarpane->setstatusicon( hicon ) following statement:

first-chance exception @ 0x00000000 in project.exe: 0xc0000005: access violation executing location 0x00000000.

however, looking @ variable trace shows there no null pointers being accessed, don't understand how can have access violation @ address 0?

thanks in advance!

note access violation not more common type attempt read or write memory address. in case error attempting execute code @ address 0x00000000. indicate calling function address null pointer.

the obvious explanation seem m_wndstatusbar.getelement(0) in fact not cstatusbarpane*. if case, , since setstatusicon virtual function, code trying perform vtable lookup on m_wndstatusbar.getelement(0). , can work if m_wndstatusbar.getelement(0) think is.


Comments