Help Please. Newbie at work. Failing. - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Programming with C++ (https://www.supportforums.net/forumdisplay.php?fid=20) +---- Thread: Help Please. Newbie at work. Failing. (/showthread.php?tid=451) Pages:
1
2
|
Help Please. Newbie at work. Failing. - TheDoctor - 10-07-2009 Hey. So, I'm new to C++. I thought why not try and get into OOP. I don't think I quite understood how they work. My program is supposed to work like an ATM machine. First off it should check user input for a name. And that's where I fail already. I just can't get it to work and I have no idea why. The errors are i.e : ISO C++ forbids initialization of member `Name' ´; making `Name' static ; invalid in-class initialization of static data member of non-integral type `std:tring' ; Code: #include <cstdlib> RE: Help Please. Newbie at work. Failing. - Code King - 10-07-2009 who has two thumbs and doesnt give a crap....bob kelso..have we met. RE: Help Please. Newbie at work. Failing. - Vorfin - 10-07-2009 (10-07-2009, 01:22 PM)Code King Wrote: who has two thumbs and doesnt give a crap....bob kelso..have we met. Sorry to spam your thread, but that was full of win. /Vorfin Out RE: Help Please. Newbie at work. Failing. - Gaijin - 10-07-2009 <sarcasam>wow Code King and Vorfin you are really helpful... </srcasam> @Topic You didn't initialize the class, take a look at the first two lines in main() and how the Check() is called, and the variable Name shouldn't be defined within the class And also your function Check is set to return a string "string Check()" but it doesn't return a string wich may cause app to shutdown, instead of printing out the success message in Check() you should return it and cout when Check() is called Code: #include <cstdlib> RE: Help Please. Newbie at work. Failing. - TheDoctor - 10-08-2009 (10-07-2009, 01:22 PM)Code King Wrote: who has two thumbs and doesnt give a crap....bob kelso..have we met. QFT (10-07-2009, 01:59 PM)NinjaGeek Wrote: <sarcasam>wow Code King and Vorfin you are really helpful... </srcasam> When I use your code, it stills gives me an error :S Error : In member function ‘std:tring User::Check(std:tring)’: AND warning: control reaches end of non-void function ??? It works though, thanks. Kind of weird output when I enter the wrong name, but still RE: Help Please. Newbie at work. Failing. - Gaijin - 10-08-2009 (10-08-2009, 08:19 AM)TheDoctor Wrote: When I use your code, it stills gives me an error :S I don't get that error, but you can avoid the error by changing string Check() to int Check() and make it return true or false Code: int Check(string x) Then you call Check within an if condition Code: if(user->Check(x)) If the function returns true you output the message http://www.ibm.com Wrote:This warning is similar to the warning described in Return with no value. If control reaches the end of a function and no return is encountered, GCC assumes a return with no return value. However, for this, the function requires a return value. At the end of the function, add a return statement that returns a suitable return value, even if control never reaches there. RE: Help Please. Newbie at work. Failing. - TheDoctor - 10-08-2009 Cheers mate RE: Help Please. Newbie at work. Failing. - Gaijin - 10-08-2009 (10-08-2009, 10:23 AM)TheDoctor Wrote: Cheers mateI'm glad I could help RE: Help Please. Newbie at work. Failing. - Goku's Nightmare - 10-08-2009 (10-07-2009, 01:28 PM)Vorfin Wrote: Sorry to spam your thread, but that was full of win. haha WIN RE: Help Please. Newbie at work. Failing. - Cppsean - 10-08-2009 You need to have a return type in the String Function it isn't a void. Cheers! Good Luck, nice to see you in the forum |