By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

problem when allocating a new object

P: n/a
Hi,

I have developped a c++ class and I have used it in different programs
without problems.

Now, I'm modifying a c++ file developped by another person (it is a
code example about how using a library) and I'd like to include in
this code my class functionality. I get an error during execution:

#include "MyClass.h";

MyClass *p=NULL;
OthersClass *p2=NULL;

int main(void){
p2 = new OthersClass( );
p = new MyClass(myconstructorarguments);
....
}

The code compiles without problem, but during execution of line

p = new MyClass(myconstructorarguments);

I get the error: "Unhandled exception at 0x0000"
In visual C I can see that operator new returns a valid memory
position (0x00bd7188), but before any line in MyClass constructor is
reached the program crashes.

Can anybody help? Thanks in advance

Mar 13 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"cpluszen" <mm*****@gmail.comwrote in message news:11**********************@c51g2000cwc.googlegr oups.com...
Hi,

I have developped a c++ class and I have used it in different programs
without problems.

Now, I'm modifying a c++ file developped by another person (it is a
code example about how using a library) and I'd like to include in
this code my class functionality. I get an error during execution:

#include "MyClass.h";

MyClass *p=NULL;
OthersClass *p2=NULL;

int main(void){
p2 = new OthersClass( );
p = new MyClass(myconstructorarguments);
...
}

The code compiles without problem, but during execution of line

p = new MyClass(myconstructorarguments);

I get the error: "Unhandled exception at 0x0000"
In visual C I can see that operator new returns a valid memory
position (0x00bd7188), but before any line in MyClass constructor is
reached the program crashes.

Can anybody help? Thanks in advance
I guess myconstructorarguments is NULL.

Mar 13 '07 #2

P: n/a
On 13 mar, 14:56, "Fred Zwarts" <F.Zwa...@KVI.nlwrote:
"cpluszen" <mmza...@gmail.comwrote in messagenews:11**********************@c51g2000cwc.g ooglegroups.com...
Hi,
I have developped a c++ class and I have used it in different programs
without problems.
Now, I'm modifying a c++ file developped by another person (it is a
code example about how using a library) and I'd like to include in
this code my class functionality. I get an error during execution:
#include "MyClass.h";
MyClass *p=NULL;
OthersClass *p2=NULL;
int main(void){
p2 = new OthersClass( );
p = new MyClass(myconstructorarguments);
...
}
The code compiles without problem, but during execution of line
p = new MyClass(myconstructorarguments);
I get the error: "Unhandled exception at 0x0000"
In visual C I can see that operator new returns a valid memory
position (0x00bd7188), but before any line in MyClass constructor is
reached the program crashes.
Can anybody help? Thanks in advance

I guess myconstructorarguments is NULL.
Hi Fred,

in fact the constructor receives 3 arguments and none is NULL

MyClass(float,float,const char*);
Mar 13 '07 #3

P: n/a
On Mar 13, 9:41 am, "cpluszen" <mmza...@gmail.comwrote:
Hi,

I have developped a c++ class and I have used it in different programs
without problems.

Now, I'm modifying a c++ file developped by another person (it is a
code example about how using a library) and I'd like to include in
this code my class functionality. I get an error during execution:

#include "MyClass.h";

MyClass *p=NULL;
OthersClass *p2=NULL;

int main(void){
Abomination! (See http://www.research.att.com/~bs/hopl2.pdf.)
p2 = new OthersClass( );
p = new MyClass(myconstructorarguments);
...

}

The code compiles without problem, but during execution of line

p = new MyClass(myconstructorarguments);

I get the error: "Unhandled exception at 0x0000"
In visual C I can see that operator new returns a valid memory
position (0x00bd7188), but before any line in MyClass constructor is
reached the program crashes.

Can anybody help? Thanks in advance
Can your constructor (or the constructors of any of its members) throw
an exception? Is it throwing an exception? One thing to try is
catching the exception:

try
{
p2 = new OthersClass( );
p = new MyClass(myconstructorarguments);
}
catch( const std::exception& e )
{
std::cout << "Exception: " << e.what() << '\n';
}
catch( ... )
{
std::cout << "Unknown exception\n";
}

You'll want to add catch clauses for any other custom exceptions (or
exception types, e.g., std::exception*) that you or OtherClass may use
that are not related to std::exception. Hopefully you'll see something
useful from that.

Alternately, you may be able to configure your debugger to stop at the
point where the exception is thrown, at which point you can inspect
the call stack and other data to see what caused it.

This problem could also be the result of a wayward pointer somewhere
else in the code (even a seemingly unrelated point).

Cheers! --M

Mar 13 '07 #4

P: n/a

"cpluszen" <mm*****@gmail.comwrote in message
news:11**********************@t69g2000cwt.googlegr oups.com...
On 13 mar, 14:56, "Fred Zwarts" <F.Zwa...@KVI.nlwrote:
>"cpluszen" <mmza...@gmail.comwrote in
messagenews:11**********************@c51g2000cwc. googlegroups.com...
Hi,
I have developped a c++ class and I have used it in different programs
without problems.
Now, I'm modifying a c++ file developped by another person (it is a
code example about how using a library) and I'd like to include in
this code my class functionality. I get an error during execution:
#include "MyClass.h";
MyClass *p=NULL;
OthersClass *p2=NULL;
int main(void){
p2 = new OthersClass( );
p = new MyClass(myconstructorarguments);
...
}
The code compiles without problem, but during execution of line
p = new MyClass(myconstructorarguments);
I get the error: "Unhandled exception at 0x0000"
In visual C I can see that operator new returns a valid memory
position (0x00bd7188), but before any line in MyClass constructor is
reached the program crashes.
I take it you mean Visual C++ (not C), right?
Can anybody help? Thanks in advance

I guess myconstructorarguments is NULL.

Hi Fred,

in fact the constructor receives 3 arguments and none is NULL

MyClass(float,float,const char*);

Does MyClass inherit from another class? If so, perhaps the constructor of
a base class is throwing an exception.

You mention "operator new". Are you overriding that? Or, are you using
placement new?

Perhaps there is an error in the construction of the OthersClass object,
which is causing a problem later, when you create a MyClass object?

What's the *actual* call you're making, and what are the class and its
constructor definitions?

You really should avoid "fake" code like "myconstructorarguments" when
posting here, because, as you've seen, it leads people to concentrate on
things which may be entirely unrelated to the problem. What's your *real*
code, and what are the *actual* arguments you're passing? Knowing that will
help us help you much better.

-Howard

Mar 14 '07 #5

P: n/a
Thank you all for your comments,

I finally achieved to find the problem...

MyClass had a member object that was automatically instantiated
(but not in the constructor)

This object belongs to a class that needs a specific library
extension to be initialized (an OpenGL driver extension called
glew) before creating any object.... that was my fault, I
didn't initialize glew before calling MyClass
- Mario

Mar 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.