I have a strange error that comes up when I compile my code:
"void Account::setType(std::string)' member function declared in class"
I am new to this site; pardon me if I am unable to get the correct formatting for this post. (I would be happy to accept any suggestions on how to improve formatting.)
The strange part is, I had many other set functions like it (with string parameters and void return types) before I added setType but I didn't get any errors about those functions. I added the setType a few days after I had written everything else.
Any help would be much appreciated.
On some implementations, <iostream> includes <string>. It's not something you should rely on - it's better to explicitly include <string> in the file that requires it - but it would explain why it was compiling.
I tried including "#include <string>" but I continued to get the error.
I will paste the rest of the function definitions, maybe there is something there that is related to the error.
No - the OP already has usingnamespace std; in the header.
Having said that, it's not a good idea to put that in the header, because it then forces every file that includes the header to bring the entirety of std:: into the global namespace. It's much better to put using statements into the .cpp file instead.
OK, thank you.
I tried including <string> in the header but not in the .cpp file, and including it in the .cpp but not in the header, and including it in both. Nothing has worked so far.
Should I add std::string as well to both files?
In your header file, you'll need to simply put std::string instead of string throughout the file.
In your source code file, you can put using std::string; which means that every time you have string, the compiler will understand that you really mean std::string.
I don't think any of this has anything to do with your original problem, though. This is just about learning good practice with using statements.
I don't have a clue what your problem is, even now that you've told us the error message in full rather than omitting the important first word.
Sorry about that, I was really tired and couldn't read properly.
Thank you for trying anyway, and thanks for the tips on the using statements. If you suddenly hit a eureka moment, please don't hesitate to let me know!