Connection Vecotrs

I have no idea why this doesn't work. I don't think there is any information missing, but I can include it if necessary. I am pretty bad with vectors, so my syntax might be a problem. Any help I get would be appreciated.

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
struct connection {
        string name, type;
        int refA, refB;
        double length;
        connection (string n, string t, int A, int B, double l) {
                name = n;
                type = t;
                refA = A;
                refB = B;
                length = l;
        }
        connection () {
                name = "";
                type = "";
                refA = 0;
                refB = 0;
                length = 0;
        }
};

struct intersection {
        double lng, lat;
        double dist;
        string state, name;
        vector<connection *> * conns;
        intersection (double ln, double la, double d, string s, string n) {
                lng = ln;
                lat = la;
                dist = d;
                state = s;
                name = n;
        }
        intersection () {
                lng = 0;
                lat = 0;
                dist = 0;
                state = "";
                name = "";
                conns = new vector<connection *>;
        }
};


.
.
.

1
2
3
4
5
6
7
8
connection * temp3 = new connection;
        while (i<(conn->size()-1)) {
                temp3 = conn->at(i);
                cout << temp3->name << " " << temp2->type << " " << temp2->refA << " " << temp2-> refB << " " << temp2->length << "\n";
                inter->at(temp3->refA)->conns->push_back(temp3);
                inter->at(temp3->refB)->conns->push_back(temp3);
                i++;
        }

> I have no idea why this doesn't work.
> I don't think there is any information missing, but I can include it if necessary
You may want to say what is the problem
Last edited on
I get a segmentation fault and it doesn't do so until the inter->at... line. I was hoping someone would just recognize some implementation of pointers that I performed.
http://www.cplusplus.com/forum/general/112111/

> vector<connection *> * conns;
¿why is `conns' a pointer?
¿why do you store pointers?

> inter->at(temp3->refB)->conns->push_back(temp3);
¿have you ever heard about Demeter's Law? http://en.wikipedia.org/wiki/Law_of_Demeter
Last edited on
Topic archived. No new replies allowed.