mercredi 21 mars 2018

pointers to vectors as class members pointers to vectors in functions

I'm a noob. Using C++ in Clion

I'm building a graph of N random nodes on a Cartesian plane

I have a simple type, node (just a point) (int x, int y)
node pt(x,y)

I have a vector of N randomly generated unique points (would this be considered ordered points btw?) vector NodeList(N);

I have a class Graph (Incomplete) which has a function GenNodelist which I have tested as a standalone program. I had a hell of a time just getting the constructor to build without compile error.

    class Graph {
        private:
            int x;
            int y;
            vector<node> NodeList;
            node *np;
        public:

         // Constructor
            Graph(): x(x),y(y),NodeList(),np(){}

           void GenNodeList(vector<node> NL(), node &np) {x,y,NodeList, &np; }

           void GenNodeList(vector<node> *NL, node *p);

}

void Graph::GenNodeList(vector<node>* NL, node* p){
                             .
                             .
                             .
...  code that builds and has been quasi tested

So everything builds and there's a "hello world" main program in the project. The 2 classes, (node & Graph: 2 headers and 2 cpp files) along with the main "hello world" build and run. Now from main() I wan to call the call the GenNode function from main. I just want to pass a pointer and have the list generate and sit in memory UN-mutable. right now. I'll build the graph off of this later. When I try to call the function nothing works. How can I build this list and access it from main() and Graph()?

main(){
    vector<node> NL(N);
    node *np;

    Graph::GenNodeList( NL, np);
}

Can't seem to figure this out.

Aucun commentaire:

Enregistrer un commentaire