本文介绍了阅读宣言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! // C指针 int y = 0; int * ptr =& y; 读作ptr是一个整数指针,指向(取 地址)整数y。 // C ++参考 int x = 0; int& ref = x; 这读到什么? TIA,Alan - 答:因为它弄乱了人们通常阅读文字的顺序。 问:为什么这么糟糕? A:Top-发布。 问:usenet和电子邮件中最烦人的事情是什么? 解决方案 " ref是对int引用的引用(是别名) for)x。 " ref是对整数变量x绑定的整数的引用。 - Richard Herring 是的。 " ref是对int引用的引用(是x的别名) 。 我知道你在说什么但是指的是 (或者绑定作为理查德·赫林写的那个)并没有真正告诉读者什么是关系是什么,imo。参考文献真的是编译器 未修饰的指针: // C ++参考 int x = 0; int& ref = x; // C指针 int y = 0; int * ptr =& y; .... //参考 cout<< x = << x<< ",ref =" << ref<< ENDL; // x = 0,ref = 0 a ++; cout<< x = << x<< ",ref =" << ref<< ENDL; // x = 1,ref = 1 //指针 cout<< y = << y<< ",* ptr =" << * ptr<< ENDL; // y = 0,* ptr = 0 (* b)++; cout<< y = << y<< ",* ptr =" << * ptr<< ENDL; // y = 1,* ptr = 1 " a ++"更优选的是(* b)++。但是我在声明参考时质疑术语的选择。 ''&''表示''的地址''(为了向后兼容C)但是在中" int& ref = x或者句法等价物int& ref = x ,如果在''地址''的背景下阅读它,那就没有任何意义。 imo," int ref =& x"更有意义。 我想知道为什么Bjarne不只是用指针解决问题 (悬挂指针,指针不指向什么,无效* 指针等)然后使用编译器来解开它们;-) Alan // C Pointerint y = 0;int* ptr = &y;Reads as "ptr is an integer pointer that points to (takes theaddress of) integer y".// C++ Referenceint x = 0;int& ref = x;What does this read as?TIA, Alan--A: Because it messes up the order in which people normally read text.Q: Why is it such a bad thing?A: Top-posting.Q: What is the most annoying thing on usenet and in e-mail? 解决方案"ref is a reference to int that refers to (is an alias name for) x"."ref is a reference to integer that is bound to integer variable x."--Richard Herring Yes. "ref is a reference to int that refers to (is an alias name for) x".I know what you''re saying but "refers to" (or "bound to" asRichard Herring writes) doesn''t really tell the reader whatthe relationship is, imo. References are really compilerundecorated pointers:// C++ Referenceint x = 0;int& ref = x;// C Pointerint y = 0;int* ptr = &y;....// Referencecout << "x = " << x << ", ref = " << ref << endl; // x = 0, ref = 0a++;cout << "x = " << x << ", ref = " << ref << endl; // x = 1, ref = 1// Pointercout << "y = " << y << ", *ptr = " << *ptr << endl; // y = 0, *ptr = 0(*b)++;cout << "y = " << y << ", *ptr = " << *ptr << endl; // y = 1, *ptr = 1"a++" is far more preferable to "(*b)++" but I question the choice of terminology in declaring a reference.''&'' denotes ''address of'' (for backward compatibility with C) but in"int& ref = x" or the syntactical equivalent "int &ref = x" , it doesn''tmake any sense if it is read in the context of ''address of''.imo, "int ref = &x" makes more sense.I wonder why Bjarne didn''t just fix the problems with pointers(hanging pointers, pointers that don''t point to anything, void*pointers, etc) and then use the compiler to undecorate them ;-)Alan 这篇关于阅读宣言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-21 19:48