graph.h
struct Edge {
int from;
int to;
unsigned int id;
Edge(): from(0), to(0), id(0) {};
};
struct Vertex {
int label;
vector<Edge> edge;
};
class Graph: public vector<Vertex> {
int gid;
unsigned int edge_size;
};
class Trans {
public:
int tid;
vector<Graph> graph;
};
vector<Trans> database; database is a global variable, then i call run_algo(database); in main function.
void run_algo(vector<Trans> &db) {
EdgeList edges;
for(unsigned int tid = 0; tid < db.size(); tid++) {
Trans &t = db[tid];
...
Graph g = t.graph[gid];
I want to ask db is a alias to database, db[tid] is a Transaction vector, but what if the difference between using Trans &t = db[tid]; and Trans t = db[tid];, since the author who write the sample using Trans &t = db[tid];, but i think it should use Trans t = db[tid];
Thanks:)
After
t is and behaves exactly as the item in db[tid], you change t, you change db[tid]
With
t is merely a copy of the item in db[tid], changing t won’t change db[tid] here.