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

testing - Detect whether test has failed within fixture -

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

android - Create single AAR file from multiple modules using Gradle -