473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with pushback function - "An Access Violation.. "

Hello,

i am new to c++,
i hav a vector of typed object:
vector<Man*People;

When i do a second pushback, even for the same object the program
crash say:
"An Access Violation (Segmentation fault) raised in your program"
what could be the problem??

many thanks.

Jul 24 '07 #1
6 2895
ha*********@gmail.com wrote:
Hello,

i am new to c++,
i hav a vector of typed object:
vector<Man*People;

When i do a second pushback, even for the same object the program
crash say:
"An Access Violation (Segmentation fault) raised in your program"
what could be the problem??
Almost anything. Please post the code that causes the problem,
preferably a whole program.

Debugging C++ isn't easy, if it was possible to fix a bug from a one
line description and an error message, then C++ programmers would get
paid a whole lot less.

Only the code will do, post it.

john
Jul 24 '07 #2
On Jul 24, 11:07 pm, John Harrison <john_androni...@hotmail.com>
wrote:
hadad.ya...@gmail.com wrote:
Hello,
i am new to c++,
i hav a vector of typed object:
vector<Man*People;
When i do a second pushback, even for the same object the program
crash say:
"An Access Violation (Segmentation fault) raised in your program"
what could be the problem??

Almost anything. Please post the code that causes the problem,
preferably a whole program.

Debugging C++ isn't easy, if it was possible to fix a bug from a one
line description and an error message, then C++ programmers would get
paid a whole lot less.

Only the code will do, post it.

john
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 ;
}
}
}

Jul 25 '07 #3
On Jul 25, 9:21 am, "hadad.ya...@gmail.com" <hadad.ya...@gmail.com>
wrote:
On Jul 24, 11:07 pm, John Harrison <john_androni...@hotmail.com>
wrote:

[Incomplete code snipped]
There's not enough code here to diagnose the problem.
The best thing to do is to pare the code down to a minimum single
*compilable* body that illustrates the problem, with an int main() and
all, and post that. This has two advantages:
1. People can copy-and-paste your code direcly and compile it
themselves;
2. In paring the code down, you will very likely see the problem
yourself.
HTH.

Jul 25 '07 #4
On Wed, 25 Jul 2007 08:21:41 +0000, ha*********@gmail.com wrote:
On Jul 24, 11:07 pm, John Harrison <john_androni...@hotmail.comwrote:
>hadad.ya...@gmail.com wrote:
Hello,
i am new to c++,
i hav a vector of typed object:
vector<Man*People;
When i do a second pushback, even for the same object the program
crash say:
"An Access Violation (Segmentation fault) raised in your program"
what could be the problem??

Almost anything. Please post the code that causes the problem,
preferably a whole program.

Debugging C++ isn't easy, if it was possible to fix a bug from a one
line description and an error message, then C++ programmers would get
paid a whole lot less.

Only the code will do, post it.

john

Here is the problematic function:

void Elections::read_votes()
{
// handeling the first ballot
Ballot * oneballot;
How is 'Ballot' defined?
oneballot = read_and_normalize_inputballot(); if (oneballot!=NULL)
What does 'read_and_normalize_inputballot()' do?
{
ballots.push_back(oneballot);
How is 'ballots' defined?
}
//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 ;
}
}
}
*Please* try and post an *entire, compilable* program that demonstrates
your problem (see the FAQ):

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

My suspicion would be that the problem is being caused by a bug in some
code that you haven't posted, but who knows?

--
Lionel B
Jul 25 '07 #5
Lionel B wrote:
On Wed, 25 Jul 2007 08:21:41 +0000, ha*********@gmail.com wrote:
>On Jul 24, 11:07 pm, John Harrison <john_androni...@hotmail.comwrote:
>>hadad.ya...@gmail.com wrote:
Hello,
i am new to c++,
i hav a vector of typed object:
vector<Man*People;
When i do a second pushback, even for the same object the program
crash say:
"An Access Violation (Segmentation fault) raised in your program"
what could be the problem??
Almost anything. Please post the code that causes the problem,
preferably a whole program.

Debugging C++ isn't easy, if it was possible to fix a bug from a one
line description and an error message, then C++ programmers would get
paid a whole lot less.

Only the code will do, post it.

john
Here is the problematic function:

void Elections::read_votes()
{
// handeling the first ballot
Ballot * oneballot;

How is 'Ballot' defined?
> oneballot = read_and_normalize_inputballot(); if (oneballot!=NULL)

What does 'read_and_normalize_inputballot()' do?
--snip--

My quess is that read_and_normalize_inputballot() returns address of
local (stack) variable. Or it uses dynamic memory in which case the
allocation size was too small.
Or something else is corrupting heap.
Those are the usual beginner mistakes.

ismo
Jul 25 '07 #6
<ha*********@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
On Jul 24, 11:07 pm, John Harrison <john_androni...@hotmail.com>
wrote:
>hadad.ya...@gmail.com wrote:
Hello,
i am new to c++,
i hav a vector of typed object:
vector<Man*People;
When i do a second pushback, even for the same object the program
crash say:
"An Access Violation (Segmentation fault) raised in your program"
what could be the problem??

Almost anything. Please post the code that causes the problem,
preferably a whole program.

Debugging C++ isn't easy, if it was possible to fix a bug from a one
line description and an error message, then C++ programmers would get
paid a whole lot less.

Only the code will do, post it.

john

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.
Jul 26 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Michael Olea | last post by:
Here is a design problem I ran into this am - and I have cleaned the bathroom, scrubbed toilet sink and tub, windexed all glass, mopped the floor, and vacuumed the house - no dice, the problem is...
1
by: CES | last post by:
All, Could someone please look at this and tell me what's wrong... the function works properly in FireFox but in IE onmouseover it replaces the innerHTML. So the original html: at info@test.com...
5
by: Mark Dicken | last post by:
Hi All, I am trying to Pass A Collection To A FUNCTION ??? (Access 2000) I have a Class called BO (for Business Objects) Within BO I have a Function called ShowCollection Public Sub...
14
by: E. Robert Tisdale | last post by:
Is a function an object?
2
by: Luke | last post by:
Hi I have the following code which is an ASP questionnaire using an Access database. (I am using access as I have no choice!). Basically there is an html form which submits the form to the page...
0
by: ss | last post by:
i read a few posts about global function access. well i am not interested in global functions. rather, i am seeking for a way to may my call in ASPX pages but not the code behind. for example:...
0
by: Yanping Zhang | last post by:
Hi All, I need to use this C routine in python and there is a void pointer parameter in it: (this routine was written by someone else): myfunc(int a, (void *)userdata, bool b) I saw someone...
2
by: embarkr | last post by:
I am getting the error: "Violation of PRIMARY KEY constraint 'PK_tblCustomsTariffTreeMap'. Cannot insert duplicate key in object 'dbo.tblCustomsTariffCodeTreeMap'." However, the record I am...
3
by: dolphin | last post by:
Hello everyone! Can a static member function access non-static member? I think it is illegal.Is it right?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.