I have a class that looks like this:
Code:
/* pdConState is going to be a base class */
class pdConState
{
public:
pdConState() { }
virtual void ProcessUserInput(pdPlayer* ch);
};
ProcessUserInput() is defined in another file.
Code:
void pdConState::ProcessUserInput(pdPlayer* ch)
{
/* Do stuff */
}
When I call it from somewhere else like this:
Code:
for (int i = 0; i < player.size(); i++)
{
pdPlayer* ch=&player.at(i);
if(ch->GetCmdBuffer()=="")
continue;
ch->GetState()->ProcessUserInput(ch);
}
The program throws a segmentation fault / STATUS_ACCESS_VIOLATION when it hits the line in bold.
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
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.