"const" is a very common key word in C++ programming language. I use lots of "const" in my previous project and now I want to write some summary about the usage of it.
I suppose there is a Class "A".
class A { public: int val; };Thanks!void test1( A & const a) { A aa; aa.val = 2; a = aa; // warning C4227: anachronism used : qualifiers on reference are ignored }
void test2(const A & a) { A aa; aa.val = 3; a = aa; // error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const A' (or there is no acceptable conversion) }
void main() { A aa; test1(aa); test2(aa);
A aaa; aaa.val =4; A & const bbb=aaa; // warning C4227: anachronism used : qualifiers on reference are ignored
}
Reference:
[1]. http://www.devmaster.net/forums/archive/index.php/t-3863.html [2]. http://faq.csdn.net/read/2143.html