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
Post a Comment