I'm studying this rudimentary string class and I have a few questions about the
Code:
overloading it uses to access a character at a certain position. Here it is:
Code:
The first overload is for read-from instances while the second is for assign-to instances. First of all, how is the function overloading determined: by the return value (which I didn't know was possible) or by whether or not the member function is const? Does the first function have to be a const member? Sorry, but const has seriously been confusing me lately and I feel it's doing more harm than good by making me trace back to see what can and cannot be changed.
Another thing; assuming the overloading is done by return value, do all assign-to situations require a reference and all read-from situations require a value by convention? If so, where can I find the specifications on what kind of function certain operators in certain situations expect for overloading? Hope that made sense. Thanks.
Code:
operator[]
Code:
class String {
protected:
char * itsString;
unsigned short itsLength;
public:
// some constructors...
// some accessors...
char operator[](unsigned short offset) const;
char & operator[](unsigned short offset);
// more methods...
};
The first overload is for read-from instances while the second is for assign-to instances. First of all, how is the function overloading determined: by the return value (which I didn't know was possible) or by whether or not the member function is const? Does the first function have to be a const member? Sorry, but const has seriously been confusing me lately and I feel it's doing more harm than good by making me trace back to see what can and cannot be changed.
Another thing; assuming the overloading is done by return value, do all assign-to situations require a reference and all read-from situations require a value by convention? If so, where can I find the specifications on what kind of function certain operators in certain situations expect for overloading? Hope that made sense. Thanks.