标签:
::
performs a (compile time) scope resolution rather than an expression evaluation.x++
and ++x
should have the same observable effect on x
, and should differ only in what they return. ++x
should return x
by reference; x++
should either return a copy (by value) of the original state of x
or should have a void
return-type.double& operator() (unsigned row, unsigned col); // Subscript operators often come in pairs
operator()
approach. Specifically, there are easy performance tuning tricks that can be done with the operator()
approach that are more difficult in the [][]
approach, and therefore the [][]
approach is more likely to lead to bad performance, at least in some cases.operator()
approach is never worse than, and sometimes better than, the [][]
approach.m(i,j)
gives you a clean, simple way to check all the parameters and to hide (and therefore, if you want to, change) the internal data structure.class Number {
public:
Number& operator++ (); // prefix ++
Number operator++ (int); // postfix ++
};
C++ Super-FAQ 『Operator Overloading』
标签:
原文地址:http://www.cnblogs.com/yanxingyoudao/p/5230374.html