How could I call a function as a pointer from an array in c++? -


so im using array of structs so:

struct node {   char* name;   int   value; };  node *nodearray = new node*[50]; 

im trying call function array can search through elements so:

struct node* newnode; newnode = nodearray->find(name); 

if name char* returns pointer node in array once name found.

how go creating class call find function array?

this how solve it, if insist on using node array class. note assume node declared in original post.

#include <vector>  class nodearray { public:     explicit nodearray(size_t length)         : nodes_(length)     {}      node* find(const char* name){         (size_t = 0; != nodes_.size(); ++i){             if (0 == strcmp(nodes_[i].name, name)){ // strcmp not pretty though.                 return &(nodes_[i]);             }         }         return null;     }      // todo: add methods filling/accessing nodes..  private:     std::vector<node> nodes_; };  int main() {     nodearray my_nodes(50);     // stuff     node* some_node = my_nodes.find("some");     if (some_node) { /* ... */ } } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -