c++ - what is the issue with the following code as I am receiving 'w' is not defined? -


i wrote class. not know why receiving w not defined, although defined that. know problem?

#include "stdafx.h" #include <iostream> #include <string> using namespace std;  class add{   public:     void counter();     void z();     string w; };  void z(){     cin>>w;      getline(cin,w);     cout<<w; }   int main(){     add s;     s.z();     cin.get(); } 

you need write void add::z(){ when defining member function void z().

else you're defining global function void z(), , w cannot found. that's confusing compiler.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -