C++ Unhandled exception at 0x00000000

A

AMT2K5

Hello, I am trying to figure out the source of this unhandled exception
(bad pointer or unallocated memory)

I have a parent class, IOField with the following pointer to function

bool (*isValid)(void *data, IOScreen *scrPtr);

This holds the address of a function that is desinged to validate the
data of an IOField after being edited. The IOField is displayed in an
IOSCreen pointed by "scrPtr".

Now later on in a child class, I want to make a function call to
isValid;

if(isValid(data,this->owner) == false) condition = true;

Previous functions allocate memory for data and store strings in them,
and this->owner is set in the constructor.

data and, this->owner has an address but isValid does not.

When compiling, the only address with 0x00000000 is isValid;

Visual Studio 2005 reports,
data 0x00129ac8 void *
+ owner 0x0012920c {fnum=15 row=2 col=5 ...}
IOScreen *
isValid 0x00000000 bool (void *, IOScreen *)*
+ this 0x00356b48 {flen=20 slen=40 curpos=0 ...}
IOLineEdit * const

Maybe I am doing something wrong with pointer to functions, I dont have
*that* much experience using them (they are required in this college
assignment).

Appreciate any help and thanks in advance.
 
A

Artie Gold

AMT2K5 said:
Hello, I am trying to figure out the source of this unhandled exception
(bad pointer or unallocated memory)

I have a parent class, IOField with the following pointer to function

bool (*isValid)(void *data, IOScreen *scrPtr);

This holds the address of a function that is desinged to validate the
data of an IOField after being edited. The IOField is displayed in an
IOSCreen pointed by "scrPtr".

Now later on in a child class, I want to make a function call to
isValid;

if(isValid(data,this->owner) == false) condition = true;

Previous functions allocate memory for data and store strings in them,
and this->owner is set in the constructor.

data and, this->owner has an address but isValid does not.

When compiling, the only address with 0x00000000 is isValid;

Visual Studio 2005 reports,
data 0x00129ac8 void *
+ owner 0x0012920c {fnum=15 row=2 col=5 ...}
IOScreen *
isValid 0x00000000 bool (void *, IOScreen *)*
+ this 0x00356b48 {flen=20 slen=40 curpos=0 ...}
IOLineEdit * const

Maybe I am doing something wrong with pointer to functions, I dont have
*that* much experience using them (they are required in this college
assignment).

Appreciate any help and thanks in advance.
Have you initialized/assigned a value to `isValid'? (It sure looks like
you haven't.)

Show us the constructors for your class and we might be able to help.

HTH,
--ag
 
A

AMT2K5

IOField::IOField(int row, int col,void (*help)(IOScreen *), bool
(*isValid)(void *, IOScreen *)):Ok(true){
this->row = row;
this->col = col;
this->help = help;
this->isValid = isValid;
this->data = NULL;
setOwner(NULL);
}



IOLineEdit::IOLineEdit(int row, int col, int flen, int slen, int *ins,
void (*help)(IOScreen *), bool (*isValid)(void *, IOScreen *)
):IOField(row,col,help,isValid){
Ok = false;
data = new char[slen+1];
if(data){
Ok = true;
dynamic = true;
curpos = spos = 0;
this->flen = flen;
this->slen = slen;
this->ins = ins;
((char*)data)[0] = 0;
}
}
 
J

John Harrison

AMT2K5 said:
Hello, I am trying to figure out the source of this unhandled exception
(bad pointer or unallocated memory)

I have a parent class, IOField with the following pointer to function

bool (*isValid)(void *data, IOScreen *scrPtr);

This holds the address of a function that is desinged to validate the
data of an IOField after being edited. The IOField is displayed in an
IOSCreen pointed by "scrPtr".

Now later on in a child class, I want to make a function call to
isValid;

if(isValid(data,this->owner) == false) condition = true;

Previous functions allocate memory for data and store strings in them,
and this->owner is set in the constructor.

data and, this->owner has an address but isValid does not.

When compiling, the only address with 0x00000000 is isValid;

Visual Studio 2005 reports,
data 0x00129ac8 void *
+ owner 0x0012920c {fnum=15 row=2 col=5 ...}
IOScreen *
isValid 0x00000000 bool (void *, IOScreen *)*
+ this 0x00356b48 {flen=20 slen=40 curpos=0 ...}
IOLineEdit * const

Maybe I am doing something wrong with pointer to functions, I dont have
*that* much experience using them (they are required in this college
assignment).

Appreciate any help and thanks in advance.

Well nowhere in this descrption have you said where you assign an
address to isValid. Also judging by your debugger output isValid has an
address of NULL. Is it possible you just forgot to assign an address to
isValid?

If this doesn't help then remove all extraneous code from your program,
so that you have a small but still compilable program which still has
this problem, then post the entire code here. It's difficult to solve
coding problems without seeing the code.

john
 
J

John Harrison

AMT2K5 said:
IOField::IOField(int row, int col,void (*help)(IOScreen *), bool
(*isValid)(void *, IOScreen *)):Ok(true){
this->row = row;
this->col = col;
this->help = help;
this->isValid = isValid;
this->data = NULL;
setOwner(NULL);
}



IOLineEdit::IOLineEdit(int row, int col, int flen, int slen, int *ins,
void (*help)(IOScreen *), bool (*isValid)(void *, IOScreen *)
):IOField(row,col,help,isValid){
Ok = false;
data = new char[slen+1];
if(data){
Ok = true;
dynamic = true;
curpos = spos = 0;
this->flen = flen;
this->slen = slen;
this->ins = ins;
((char*)data)[0] = 0;
}
}

Well there is nothing wrong with that code. But somewhere in your
program you have a bug. This could take a while.

Please have a look at the guidelines for posting code

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8

Follow those recommendations and you'll have a solution very quickly

john
 
A

AMT2K5

I see how isValid is NULL which I dont understand since I set it in the
parent constructor

this->isValid = isValid
 
J

Jim Langston

AMT2K5 said:
I see how isValid is NULL which I dont understand since I set it in the
parent constructor

this->isValid = isValid

Yes, but you are assuming that the isValid passed in isn't null.

Put a debug break on that line.

Then debug the program. What is the value of the isValid you are passing
in? I'll bet you it's null.
 
J

Jim Langston

AMT2K5 said:
Correct, yes it is.

Well, so now you know your problem, right? You're passing null in. Find
out where you're passing it in, and find out why you're passing null.
 
A

AMT2K5

Trying to understand what you said, I think the problem lies within the
= NULL defaults im using in the class definition?

public:
IOLineEdit( char *str, int row, int col, int flen, int slen,
int *ins = NULL, void (*help)(IOScreen *) = NULL,
bool (*isValid)(void *, IOScreen *) = NULL);
IOLineEdit(int row, int col, int flen, int slen, int *ins = NULL,
void (*help)(IOScreen *) = NULL,
bool (*isValid)(void *, IOScreen *) = NULL);
 
J

Jim Langston

AMT2K5 said:
Trying to understand what you said, I think the problem lies within the
= NULL defaults im using in the class definition?

public:
IOLineEdit( char *str, int row, int col, int flen, int slen,
int *ins = NULL, void (*help)(IOScreen *) = NULL,
bool (*isValid)(void *, IOScreen *) = NULL);
IOLineEdit(int row, int col, int flen, int slen, int *ins = NULL,
void (*help)(IOScreen *) = NULL,
bool (*isValid)(void *, IOScreen *) = NULL);

What that means is, "if I don't pass any parameter in this slot, make the
parater this value." So if you don't pass a parameter in the slot for
isValid, it will assign isValid the value of NULL.

So, where are you calling IOLineEdit? It might be a constructor (proably
is) so how you are instatizing IOLineEdit?

Like, IOLineEdit MyVar(10, 20, 30, 40); or? Look at the line where you are
instatizing the IOLineEdit object. Look at the parameters you are passing
in. Are you passing a parameter in for the isValid parm? (8th parm for
your first constructor, 7th parm for you're 2nd constructor).
 
M

Mike Smith

AMT2K5 said:
I see how isValid is NULL which I dont understand since I set it in the
parent constructor

this->isValid = isValid

And what is the "isValid" on the RHS? Where does its value come from?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top