I have a class that looks like this:
ProcessUserInput() is defined in another file.Code:/* pdConState is going to be a base class */ class pdConState { public: pdConState() { } virtual void ProcessUserInput(pdPlayer* ch); };
When I call it from somewhere else like this:Code:void pdConState::ProcessUserInput(pdPlayer* ch) { /* Do stuff */ }
The program throws a segmentation fault / STATUS_ACCESS_VIOLATION when it hits the line in bold.Code:for (int i = 0; i < player.size(); i++) { pdPlayer* ch=&player.at(i); if(ch->GetCmdBuffer()=="") continue; ch->GetState()->ProcessUserInput(ch); }
However, making the function a plain function instead of a virtual one stops the crashing. After doing some Googling, I'm guessing that it has something to do with virtual functions being dynamically bound instead of statically bound, but I still have no idea of how to fix the problem.Code:Program received signal SIGSEGV, Segmentation fault. 0x004047ac in pdmud::pdmudServer::ProcessInput (this=0x28cc78) at pdmud.cxx:111 111 ch->GetState()->ProcessUserInput(ch); (gdb) n 12 [main] pdmud 1764 exception::handle: Exception: STATUS_ACCESS_VIOLATION 1321 [main] pdmud 1764 open_stackdumpfile: Dumping stack trace to pdmud.exe.stackdum



LinkBack URL
About LinkBacks




operator. In this case, the virtual function call mechanism is suppressed and the function implementation defined in the base class is used. In addition, if you do not override a virtual member function in a derived class, a call to that function uses the function implementation defined in the base class.
