function stopping whenever encountering a system("PAUSE")

Like title says, my program is stopping whenever it hits system("PAUSE") in my code. I have strong reason to believe that it is not the system("PAUSE") that is causing the crash...based on the fact that when I take system("PAUSE"), the program still crashes.

To make things a little more specific, the problem occurs in a situation similar to (but not as simple as) the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cstdlib>
#include <iostream>

#include <fstream> 
#include <vector>
#include <string>

class First_Class
{
public:
     int number1;
     int number2;
};

class Second_Class
{
public:
     vector<First_Class *> first_class_vector;
};

class Third_Class
{
public:
     vector<Second_Class *> second_class_vector;
};

//so, there's a class containing a vector containing classes that contain //another vector containing classes that contain two int's

void First_Function(Second_Class *second_class)
{

     for (int i=0; i<second_class.size(); i++)
     {
          second_class.first_class_vector[i]->number1 += 1;
          second_class.first_class_vector[i]->number2 += 1;
     }
}

void Second_Function(Third_Class *third_class)
{
     First_Function(third_class.second_class_vector[0]); //ish..probly wrong //syntax
}

int main()
{
     Third_Class third_class;
     Second_Class second_class;
     First_Class first_class;

     first_class.number1 = 0;
     first_class.number2 = 0;

     second_class.first_class_vector.push_back(&first_class);
     third_class.second_class_vector.push_back(&second_class);

     Second_Function(&third_class);

     return EXIT_SUCCESS;
}


If the above code mirrors my program, the above code would crash during First_Function. If you slap a system("PAUSE") in First_Function, it will just crash at the system("PAUSE"). Is there some common thing that might cause my program to crash at a system("PAUSE") (or anywhere during the function, for that matter)? Is it possible that there is a memory overflow or something?

Yes, yes, I know lines like system("PAUSE") are no good for portability, but it's just for temporary debugging. Any help would be awesome, I'm almost certain that I will get no further with bug-testing by myself.

EDIT: Since it doesn't seem to be clear: The above program is, as the layman may deduce, NOT my actual program code. It's just an example that illustrates the problem that I'm having.
Last edited on
How is it possible that it crashes? It cannot even compile.

On line 53/54 the vectors expects a pointer to the object but you pass the object itself.

In First_Function() you access the second_class completely wrong
On line 53/54 the vectors expects a pointer to the object but you pass the object itself.

In First_Function() you access the second_class completely wrong


This.
Thanks for pointing that out coder777, I made an edit above. I assure though you that the actual program DOES compile, unlike the example version above.

To make it more clear, I am wondering this: In a situation SIMILAR TO (but not identical to) the above program, would there be issues with running the program? Is there any chance that the program would have a problem with memory overflow, or some problem that I am unfamiliar with? This of course is all assuming that the program does indeed compile, and is free of syntax errors.

No, I didn't take the time type my example code into a compiler. I don't need a program that does almost nothing like the one above. I just wanted some example code that looks like the much-larger version that I'm trying to run, that's all.
It isn't right. Many times you use . instead of ->. And second_class->size isn't right, it should be second_class->first_class_vector.size.
It isn't right. Many times you use . instead of ->. And second_class->size isn't right, it should be second_class->first_class_vector.size.


Ok Ok. I understand. The code above is complete and utter TRASH. GARBAGE. FILTH, shameful to look upon.

My question still stands...please somebody answer it...more specifically regarding my question about memory overflow, or problems when dealing variables within classes that go very deep?

Why are you using system pause? Why not use a break point, why not use Sleep(), do you need pause?

http://www.gidnetwork.com/b-61.html
SheerSt wrote:
My question still stands...please somebody answer it...more specifically regarding my question about memory overflow, or problems when dealing variables within classes that go very deep?


It's hard/impossible for us to tell what you're doing wrong when you don't show us what you're doing.

Your original post is basically saying "I'm doing something like this, but ignore all the errors in this code". But if we are supposed to be ignoring errors, how can we find the error?

If you don't want to post your entire code, the next thing to do is produce a smaller, compilable and runnable program which actually does reproduce the problem.

Once you post that, we can help you solve it. Until then, we have no way to know what's going on.
Last edited on
^ this. You can't actually expect us to figure out what's wrong if you don't actually show us what you're doing. This isn't nitpicking - if you can't show us code that produces the problem you described, how are we ever gonna find out what's wrong?
Topic archived. No new replies allowed.