0
Why this shows no output just by replacing x =name instead of name = x in this code ?
#include <iostream> using namespace std; class myClass { public: myClass(string nm) { setName(nm); } void setName(string x) { name = x; } string getName() { return name; } private: string name; }; int main() { myClass ob1("David"); myClass ob2("Amy"); cout << ob1.getName(); }
1 Odpowiedź
+ 1
And why would it show any value? You wanna assign name to x, where x is destroyed at the end of a function scope.