+ 2
Wth is wrong with this code? I think my colons, semicolons and brackets are okay. How is 'idnumber' not declared in this scope?
class id {public: id (int a) {setidnumber(idn);} void setidnumber(int x) {idnumber = x; } string getresidence() {return residence;} private: string residence;}; int main() {id ob1 ("1234"); id ob2 ("3456"); cout << ob1.getresidence();}
4 Antworten
+ 3
u need a private variable idnumber to store the id number (hehe) and on id constructor is setidnumber(a); not setidnumber(idn) couse idn isnt defined, also in main remember that anything within coutes are strings so "1234" is not an int.
+ 3
Lol. Thanks, Hector. That was easy. Though it works with setidnumber(idn) too. Thank you.
+ 3
luka, i don't code that way, though. i just put it that way to post here