What may cause a program to stop?

Hi guys.

First, I want to compliment the forum members for their patience and helpful answers. I always fill that I'm not doing that enough.

Now, to my question.

In my program, I have a myVec class (which I think I already mentioned in this forum). Usually, there is no problem with this class, however there is one point in the program that stop once I create such a class member, the line is simply,

myVec r;

I tried to debug the line and the constructor and the only weird part I read is that the line

length = LENGTH

where I used

#define LENGTH 3

does not show that the value of length has changed in the debugger (I tried to print the value of length but no message is printed).

Any thoughts?

Thanks.

I think most people are going to need a little more code to see what might be going on.
I'm not very familiar with using #define but when you use

#define LENGTH 3 // It defines LENGTH to 3

but do you have or do you need to have

length = LENGTH //before #define LENGTH 3



Because if length doesn't output anything, you might have not defined LENGTH after you give the value to it.

But I'm not sure.
On top of what Galik said, prefer const's to #define 's.
I can't post the code up until tomorrow but I don't think it would be any help. The myVec constructor is something of the sort:


1
2
3
4
length = LENGTH
coor = new double[length]
for (int i = 0; i<length; i++){
coor[1] = 0;


I want to mention again that the constructor does work on most of the code but on a specific part of the code it doesn't work. I am sure that the problem is not with the constructor and I can't think where the problem might be and this is what I'm asking for, what might cause a constructor to work perfectly well in one part but kill the program in another part?

As for the const usage, I have a single header file where I place all the constant of the program, including the LENGTH (includer.h). I just explained what LENGTH is.

Hope I'm clear.

Yotam
Did you cut'n'pase this code?
 
coor[1] = 0;
No, I wrote it out of my head. I'm at home now, while the code is written on a computer in the university.

Sorry.
This loop cause me the problem. Note that I don't call the ball2 function in any stage (at least I dont think I do and I'm only coping the memory address from place to place. On my machine (mac mini, eclpise IDE) the line myVec r cause the machine to get stuck in the loop (I think) and I see the program doesn't finnish running. If I replace myVec r with myVec * r, the program acts normal (atlist I think so).

1
2
3
4
5
6
7
8
9
10
11
12
vector<ball2*>::iterator iter = balls.begin();
vector<ball2*>::iterator otherIter;

while (iter!=balls.end()){
	ball2 * thisBall = *iter;
	otherIter = other->getBalls().begin();
	while(otherIter != other->getBalls().end()){
		myVec r;
		otherIter++;
	}
iter++;
}
Last edited on
Can you show us the code for myVec?
This is my constructor:

myVec::myVec() {
length = LENGTH;
coor = new double[length];
coor[0] = 0;
coor[1] = 0;
coor[2] = 0;
// TODO Auto-generated constructor stub

}

I have used the coor[0] only because it is easier to see (for me). As for now I know that I should used coor = new double [3] but I want the code to be changeable easily.

Yotam

thank you everyone for such answers....after reading the posts got many ideas about executing the codes...u can even make the codes shorter...try it...


__________________________________________________________________
Want to get-on Google's first page and loads of traffic to your website? Hire a SEO Specialist from Ocean Groups [url=http://oceangroups.org/]seo pecialist [/url]
Topic archived. No new replies allowed.