J
James Angi
I have a question on operator overloading that I can't find an answer to in
several guides (even google has failed me).
I'm currently making my way through several C++ guides, trying to become
familiar with the language's features. The book I'm in the middle of right
now says an operator+ function cannot be const. For example, it seems to
imply:
class String {
public:
String operator+(const String&) const;
};
is invalid... yet it compiles, works fine, and while I realize that this
does not mean it is 'correct', I can't think of a reason why an operator+
method could not be declared const.
Thanks,
James
several guides (even google has failed me).
I'm currently making my way through several C++ guides, trying to become
familiar with the language's features. The book I'm in the middle of right
now says an operator+ function cannot be const. For example, it seems to
imply:
class String {
public:
String operator+(const String&) const;
};
is invalid... yet it compiles, works fine, and while I realize that this
does not mean it is 'correct', I can't think of a reason why an operator+
method could not be declared const.
Thanks,
James