c++ - Problems with understanding scope -


i|m having problems understanding scope of class or function. program incomplete not being able use function within same class , different class. example: error says

"'selector' not declared in scope"

can me figure out what's wrong? thanks

#include <iostream> using namespace std;         int main(void){ selector();  }    void selector(){     linkedlist test;     /* block of code */             }    class linkedlist{    node *head;  public:   linkedlist(){     head = null;     }     //other lines  };  class node{ public:     int data;     node * next; } 

i don't understand why you're talking classes, scope of function declaration end of file. swap 2 functions in code:

void selector() {     // linkedlist test;     /* block of code */            }  int main() {     selector();  // selector in scope here } 

(i'm not sure why you're doing int main(void) either. that's more of c thing. c++ function no arguments looks int main().)


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -