Here is the problematic function:
void Elections::read_votes()
{
// handeling the first ballot
Ballot * oneballot;
oneballot = read_and_normalize_inputballot();
if (oneballot!=NULL)
{
ballots.push_back(oneballot);
}
//handeling the rest of the ballots
string command;
while (cin>>command)
{
if (command=="InputBallot")
{
oneballot = read_and_normalize_inputballot();
if (oneballot!=NULL)
{
ballots.push_back(oneballot); - crash here!!!!!,
ballots is not null neither.
}
}
else
{
return ;
}
}
}
This code, in and of itself, should not produce a problem, so it must be
somewhere we can't see. Such as in read_and_normalize_inputballot();
Please post complete compilable code that reproduces the problem. In this
case include read_and_normalize_inputballot();, definition of ballots, and a
main that executes and causes the error.
I suspect that just by you doing this you'll find the problem. Or when you
do this, you'll find it's no longer crashing, and find the error is
elsewhere.
Access violations gernally mean that the computer is trying to read memory
it doesn't "own", that something is pointing to somewhere it shouldn't. A
lot of things can cause this, not only a pointer just pointing to somewhere
it shouldn't, but heap/stack corruption, array overflows, etc... Usually
reducing the code to the smallest code that reproduces the problem shows the
error, as when you take something thought to be unrelated out it suddently
starts to work.