Hi,
I've been trying to debug a strange runtime error for the last 5
hours... I'm hoping someone might have an insight about it.
I have an application that creates a vector of MyDisplay objects
(MyDisplay is a custom class) and then uses them in various ways. The
application has been compiling and running fine. Then I added a
member variable of type enum to MyDisplay. So my class def now looks
like this:
class MyDisplay {
enum DisplayType {SMALL,MEDIUM,L ARGE};
private:
DisplayType _displayType;
//....
// all the rest of the def is the same as before
}
I also added a default value in the constructor initialization list:
MyDisplay::MyDi splay() : _displayType(ME DIUM),
//rest of ctor def is same as before
Those are the ONLY two changes I've made so far. The app still
compiles without error. However, it now crashes when I run it. (If I
remove those changes, it will run perfectly). In particular, it
crashes when the vector of MyDisplay objects is being created. The
code creates 10 of them in total, and it crashes after the fourth one
has been constructed and added to the vector.
However, there does not seem to be a memory overload. The app never
uses more 3.5 MG memory, and each MyDisplay adds less than
200K.
PLEASE NOTE: I know that I'm leaving many possibly relevant details
out of my description, but it would be too much to ask anyone to look
at the whole app, as its fairly large. I'm just hoping that the
description above might ring some bells for someone.
Thanks for any thoughts,
cpp 7 1950
* cppaddict: I've been trying to debug a strange runtime error for the last 5 hours... I'm hoping someone might have an insight about it.
I have an application that creates a vector of MyDisplay objects (MyDisplay is a custom class) and then uses them in various ways. The application has been compiling and running fine. Then I added a member variable of type enum to MyDisplay. So my class def now looks like this:
class MyDisplay { enum DisplayType {SMALL,MEDIUM,L ARGE}; private: DisplayType _displayType; //.... // all the rest of the def is the same as before }
I also added a default value in the constructor initialization list:
MyDisplay::MyDi splay() : _displayType(ME DIUM), //rest of ctor def is same as before
Those are the ONLY two changes I've made so far. The app still compiles without error. However, it now crashes when I run it. (If I remove those changes, it will run perfectly). In particular, it crashes when the vector of MyDisplay objects is being created. The code creates 10 of them in total, and it crashes after the fourth one has been constructed and added to the vector.
Most probably the problem is with the definition of DisplayType.
Does it support copy construction? Does it support assignment? Those
are requirements of std::vector, if I recall correctly.
Btw., it's a good idea to always use all uppercase names for _macros_,
and never for anything else (it's a convention that avoids name clashes).
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Alf,
Thanks for you reply. Could you clarify one point? Most probably the problem is with the definition of DisplayType.
Does it support copy construction? Does it support assignment? Those are requirements of std::vector, if I recall correctly.
DisplayType is just an enum defined inside MyDisplay (which is the
type that the vector is made up of). I didn't think that you would
make a copy constructor of an enum type. Am I wrong here?
Btw., it's a good idea to always use all uppercase names for _macros_, and never for anything else (it's a convention that avoids name clashes).
Thanks for the tip. Is there a standard way to indicate an constant?
That's what I was trying to do.
Thanks again,
cpp
* cppaddict: Alf,
Thanks for you reply. Could you clarify one point?
Most probably the problem is with the definition of DisplayType.
Does it support copy construction? Does it support assignment? Those are requirements of std::vector, if I recall correctly.
DisplayType is just an enum defined inside MyDisplay (which is the type that the vector is made up of). I didn't think that you would make a copy constructor of an enum type. Am I wrong here?
Mea culpa. I didn't connect the two things.
The following compiles & runs fine; perhaps you can add more and more
in an effort to identify the problem:
#include <vector>
class MyDisplay
{
private:
enum DisplayType {SMALL,MEDIUM,L ARGE};
DisplayType _displayType;
public:
MyDisplay(): _displayType(ME DIUM) {}
};
int main()
{
std::vector<MyD isplay> v( 10 );
std::vector<MyD isplay> v2 = v;
}
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
"cppaddict" <he***@hello.co m> wrote in message
news:om******** *************** *********@4ax.c om... Hi,
I've been trying to debug a strange runtime error for the last 5 hours... I'm hoping someone might have an insight about it.
I have an application that creates a vector of MyDisplay objects (MyDisplay is a custom class) and then uses them in various ways. The application has been compiling and running fine. Then I added a member variable of type enum to MyDisplay. So my class def now looks like this:
class MyDisplay { enum DisplayType {SMALL,MEDIUM,L ARGE}; private: DisplayType _displayType; //.... // all the rest of the def is the same as before }
I also added a default value in the constructor initialization list:
MyDisplay::MyDi splay() : _displayType(ME DIUM), //rest of ctor def is same as before
Those are the ONLY two changes I've made so far. The app still compiles without error. However, it now crashes when I run it. (If I remove those changes, it will run perfectly). In particular, it crashes when the vector of MyDisplay objects is being created. The code creates 10 of them in total, and it crashes after the fourth one has been constructed and added to the vector.
From my experiance, a problem like this is usually caused by apparently
unrelated code. Often, it is caused by writing past the end of a local
array. When you do that, you trash the memory beyond the array's bounds,
which may or may not cause problems (at least not obvious ones, especially
in a debug build). When you later add something to the program, suddenly
that memory location just beyond the array becomes important, and
overwriting it causes a crash.
I'd look very carefully for something like this. I can't say how many times
I've seen it happen. Not that *I've* ever written beyond the end of an
array, of course! ;-)
-Howard
****UPDATE****
I have tried chaning the data type of _truncType to int.
When I do so I still see the problem, which means that it is not
specific to enum, but simply due to adding a new data member. Please
let me know if that gives you any new ideas. From my experiance, a problem like this is usually caused by apparently unrelated code. Often, it is caused by writing past the end of a local array. When you do that, you trash the memory beyond the array's bounds, which may or may not cause problems (at least not obvious ones, especially in a debug build). When you later add something to the program, suddenly that memory location just beyond the array becomes important, and overwriting it causes a crash.
I'd look very carefully for something like this. I can't say how many times I've seen it happen. Not that *I've* ever written beyond the end of an array, of course! ;-)
Howard,
Thanks for thoughts.
Two things:
1. It couldn't be an array problem per se, because my code only uses
vectors.
2. Nevertheless, it may be a problem similar to what you describe.
Can you offer any ideas about specific things I should be on the alert
for?
thanks again,
cpp
On Tue, 13 Jul 2004 21:01:19 GMT in comp.lang.c++, cppaddict
<he***@hello.co m> wrote, 1. It couldn't be an array problem per se, because my code only uses vectors.
It could easily be a ~"array problem"~ if you use vector::operato r[]
since the subscript is unchecked just as for bare naked arrays.
Try changing some or all of your operator[] to vector::at(). It could easily be a ~"array problem"~ if you use vector::operato r[] since the subscript is unchecked just as for bare naked arrays. Try changing some or all of your operator[] to vector::at().
Thanks for that tip.
It turns out that the problem was much more mundane: My Makefile was
not updating one of the files that needed to be updated, so it was
using an outdated object file.
Thanks anyway for your help,
cpp This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Allcomp |
last post by:
Hello,
I have seen something really strange in VB6
If I do a Int ( (5 * 1.2)) , I receive the value 5, but I should receive 6?
Is this a bug or something really "normal".
I can see that if I do
? int ((5 * 1.2 + 0.0000000000000003))
I receive 6. If I add something smaller, I have 5 as a result
What is strange is that If I do a ? 5*1.2, I receive 6 so (5 * 1.2)
|
by: kajol |
last post by:
Hi everyone
I am trying to get the content of any webpage (URL) using XMLHTTP, and it
is working fine for me, but suddenly I have got
a URL "http://www.bizrate.com/" which is causing a system error and the
error is
System.Runtime.InteropServices.COMException(0xC00CE56E): System error:-
1072896658
|
by: Bruno van Dooren |
last post by:
Hi All,
i have some (3) different weird pointer problems that have me stumped. i
suspect that the compiler behavior is correct because gcc shows the same
results.
----------------------------------------------
//example 1:
typedef int t_Array;
int main(int argc, char* argv)
|
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much appreciated.
Thanks in advance
|
by: Lawrence Oluyede |
last post by:
I have a list of strings and i'd like to build up an
enum from them... is there a way to do that?
Thanks in advance.
--
Lawrence "Rhymes" Oluyede
http://loluyede.blogspot.com
| |
by: Sampson |
last post by:
I have a question about enumeration and how to populate them during
runtime.
I am using vb.net but will happily take any advice in c# as well.
Here is an example to help illustrate what I am after.
Create a class named “clsMyItems” and in that class place an enum.
Public Enum Items
Item1 = 0
Item2 = 1
Item3 = 2
|
by: Dirk Theune |
last post by:
Hi,
when compiling with debug information, I get an error:
fatal error C1067: compiler limit : debug information module size exceeded
The error is caused by a very large enum (about 2000 elements) which comes
from a referenced component.
Is there any workaround to make a debug build and keep the enum?
|
by: r.z. |
last post by:
My program behaves very strange. I keep getting the following error:
'The instruction at "some address" referenced memory at "some address". The
memory could not be written"'
The program consists of:
int main( int argc, char* argv )
{
//here is some third party function that configures graphic environment
{
app my_app; //this is local so that I'm sure it's destroyed before
next step
|
by: David |
last post by:
I'm using the AxSHDocVw.WebBrowser control to download data from a webpage
at work (it's an internal page on my company's intranet).
The page produces a runtime error after a while and the strange thing is
that until the page is refreshed with Internet Explorer, the error keeps
occurring. I realize no one can debug an application that I can't even
provide details about (I didn't write nor do I have access to it) but what
difference...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |