473,480 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem when allocating a new object

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
5 1656
"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
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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1758
by: August1 | last post by:
This is a short program that I have written from a text that demonstrates a class object variable created on the stack memory and another class object variable created on the heap memory. By way...
7
2079
by: boss_bhat | last post by:
Hi all , I am beginner to C programming. I have a defined astructure like the following, and i am using aliases for the different data types in the structure, typedef struct _NAME_INFO {...
6
3235
by: Tom | last post by:
I try to write a simple tcp based job queue server. It's purpose is to get commands from a client and store them in a queue (STL). The server has a thread which checks periodically the queue,...
7
2089
by: Mike P | last post by:
I read somewhere that if you are concatenating more than 2 or 3 strings you should use StringBuilder as it will use up less resources. Does this apply when you are building up a string (for...
4
4261
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
7
3736
by: ds | last post by:
Hello all, I have a problem with calloc I have never seen before. I am migrating some C code to C++ and at some part in the C code there is a calloc that creates an array of structures. Now in...
6
5148
by: Francois Grieu | last post by:
Hello, I'm asking myself all kind of questions on allocating an array of struct with proper alignment. Is the following code oorrect ? I'm most interested by the statement t =...
46
2127
by: Carlo Milanesi | last post by:
Hello, traditionally, in C++, dynamically allocated memory has been managed explicitly by calling "delete" in the application code. Now, in addition to the standard library strings, containers,...
6
218
by: asm23 | last post by:
Hi, everyone, I'm learning <<thinking c++>volume Two, and testing the code below. ///////////////////////////////////////////////////////////////////////////// //: C01:Wrapped.cpp #include...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7059
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7103
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...
1
6758
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7010
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3011
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3003
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.