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(); }

23rd Jul 2019, 5:31 AM
Rahul Singhania
Rahul Singhania - avatar
1 ответ
+ 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.
23rd Jul 2019, 5:44 AM
Jakub Stasiak
Jakub Stasiak - avatar