Trying to address everything at one go here.
Quote:
Im getting towards the end of my first attempt at this project. Although I might end up rewriting it a few times before I am happy. How would you recommend to handle eronious input? I come from a java background and there an exception would be thrown, is this similar to how C++ works?
Yes, C++ has exceptions. I'm not a Java programmer, so I can't tell you how they are different from Java's, but I'm sure there are some differences. However, you should make a distinction between 'errors' and 'exceptions'. Reserve the exception mechanism for truly exceptional situations. Errors are not things that might happen if the moon is full on tuesday; they are things that WILL happen. It's usually prudent to handle them through more conventional means, or you needlessly complicate the code.
Quote:
Another thing is using inline for functions like,
inline std::string Item::getName() const
{
return itemName;
}
Is that worth doing?
Defining the function inside the header (Yes, that's okay - for class members) gives it an implicit inline. I wouldn't bother with placing a 'get' function that just returns a member into the CPP file. Furthermore, understand that declaring a function inline does not mean it will be inlined. It's a suggestion to the compiler. It's been shown that some modern compilers - MSVC in particular - simply ignore it, and inline what's safe and sensible to inline. It's usually better to let the compiler decide - it can even inline some calls and not others. If you're really sure you know what you're doing, and a profiler has told you inlining is a good idea, and the compiler isn't already doing it for you anyway, your compiler probably has an extension to force inlining. In MSVC, it's the '__force_inline_' macro (Or something like that. MSDN is your friend.)
Not then, the actual get function - that opens a whole 'nother can of worms. It's one of the (fairly common) religious wars that pop up in the 'for beginners' and 'general programming' forums every month or so. Just keep a watch out for the next one, and read what the people with high ratings say.
Quote:
I feel a little confused because in the book, examples using the free-store appear to be all confined to a single main function(I think?), whereas in this project I'll (obviously) being running class methods in all sorts of different functions.
You can place globals in headers using the 'extern' keyword. I'm certain the book covers it.
It's pretty simple. Inside the header, you would declare the variable like 'extern int my_global;'. Then in 1 and only 1 source file, place 'int my_global;'. Any file that includes that header can access 'my_global'.
But just because you can do this doesn't mean you should. See if you can figure out how to do it using no globals at all.