 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
AMT2K5 Guest
|
Posted: Sun Nov 27, 2005 4:12 pm Post subject: C++ Unhandled exception at 0x00000000 |
|
|
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.
|
|
| Back to top |
|
 |
Artie Gold Guest
|
Posted: Sun Nov 27, 2005 4:27 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
AMT2K5 wrote:
| Quote: | 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
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
|
|
| Back to top |
|
 |
AMT2K5 Guest
|
Posted: Sun Nov 27, 2005 4:31 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
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;
}
}
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Sun Nov 27, 2005 4:32 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
AMT2K5 wrote:
| Quote: | 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
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Sun Nov 27, 2005 4:38 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
AMT2K5 wrote:
| Quote: | 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
|
|
| Back to top |
|
 |
AMT2K5 Guest
|
Posted: Sun Nov 27, 2005 4:44 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
I see how isValid is NULL which I dont understand since I set it in the
parent constructor
this->isValid = isValid
|
|
| Back to top |
|
 |
Jim Langston Guest
|
Posted: Sun Nov 27, 2005 4:55 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
"AMT2K5" <Aaron.Train (AT) gmail (DOT) com> wrote
| Quote: | 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.
|
|
| Back to top |
|
 |
AMT2K5 Guest
|
Posted: Sun Nov 27, 2005 4:58 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
Correct, yes it is.
|
|
| Back to top |
|
 |
Jim Langston Guest
|
Posted: Sun Nov 27, 2005 5:11 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
"AMT2K5" <Aaron.Train (AT) gmail (DOT) com> wrote
| Quote: | 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.
|
|
| Back to top |
|
 |
AMT2K5 Guest
|
Posted: Sun Nov 27, 2005 5:18 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
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);
|
|
| Back to top |
|
 |
Jim Langston Guest
|
Posted: Sun Nov 27, 2005 5:37 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
"AMT2K5" <Aaron.Train (AT) gmail (DOT) com> wrote
| Quote: | 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).
|
|
| Back to top |
|
 |
Mike Smith Guest
|
Posted: Tue Nov 29, 2005 8:58 pm Post subject: Re: C++ Unhandled exception at 0x00000000 |
|
|
AMT2K5 wrote:
| Quote: | 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?
--
Mike Smith
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|