lines 4-19, which hold the Stock class declaration, would preferably be found in their own header file, e.g. Stock.h , behind an include guard.
Your post has both the declaration and the implementation in the same file, which is still valid.
Line 18 could be written without the scope as const Stock& topval(const Stock& s) const; , since topval method is already inside the brackets of class Stock { ... } . The implementation of the Stock methods below that all need to start with Stock:: to show that they're implementing something from the Stock class (otherwise it would be a global method).
topval looks like it's simply comparing the current object's Stock to another Stock object (named s) topval takes a constant reference to another Stock to show that it will not attempt to change this argument. More specifically, it's comparing values between this stock and another, returning the bigger one.
Thanks very much for your reply. This is an adaption of another program which did include header files etc. I put it like this to try to make it easier for me to see what is going on. Your explanation about topval comparing values helped me a lot to understand how the this pointer was working. However, when I tried getting rid of the scope resolution operator and substituting in: const Stock& topval(const Stock& s) const;
in the class and the definition, I got this compiler error message:
modifiers not allowed on nonmember functions.