Comments (5)
请区分一下声明与赋值.
int& r1 = v2;
肯定是不行的, 原因你说了. 但 r1 = v2;
中, r1
只不过是2.30 里 v1
的别名, 相当于是给 v1
赋予 v2
的值, 有何不可?
可用下述代码在编译器中验证:
#include <iostream>
int main()
{
const int v2 = 0; int v1 = v2;
int &r1 = v1;
r1 = v2;
}
from cppprimer.
嗯,是我搞错了,r1她变了。你的回复里笔误写成“r1 = r2”了。我还有个问题是exercise2.35的那段代码的,不知道你代码里注释中的PKi是怎么在控制台显示出来的,我在vs2013里输入
cout << typeid(const int).name() << endl; 和
cout << typeid(int).name() << endl; 控制台都是int型,然后我查了一下http://stackoverflow.com/questions/8888960/why-typeid-returns-that-int-and-const-int-are-same-types
说是typeid会忽略掉const,所以好像比不出来,看另一个人说用is_name就又查了下http://www.cplusplus.com/reference/type_traits/is_same/
感觉用is_name更准点儿。朋友,我没鸡蛋里挑骨头的意思啊,以后还得向你多学 :)
from cppprimer.
你的回复里笔误写成“r1 = r2”了。
的确笔误了,感谢纠正。
不知道你代码里注释中的PKi是怎么在控制台显示出来的
typeid(p).name()
将输出 PKi, 手头没有 vs ,但在 gcc/clang 中验证。
感觉用is_name更准点儿
嗯, 学习了, 这个 is_name
的确更适合这道题, 方便的话, 可以提交一个 PR 来修改嘛?
朋友,我没鸡蛋里挑骨头的意思啊,以后还得向你多学 :)
欢迎多挑骨头, 问题还很多, 互相学习~
from cppprimer.
PR是什么啊?
from cppprimer.
PR是什么啊?
from cppprimer.
Related Issues (20)
- ex16_29 include error file,It compile failed HOT 2
- about 16.2.7 HOT 2
- Exercise 7.36
- Exercise 6.53
- Exercise 5.3 correct answer HOT 1
- Ex 6_8 HOT 1
- Ex 6_9 (added #include "fact.cpp")
- Ex 6_10 (added "return 0;")
- Exercise 13.37
- Answer to Exercises 3.37 is not entirely true.
- Ex16.49
- The new soulution of Exercise 5.12
- Ex.7.53 will not compile under the C++14 standard
- #include<exception>
- ex7_22.h 'class' instead of 'struct'
- Bug report exercise 16.12
- An error in exercise 16.28, in file <unique_pointer.h>
- Small modification for answer of Exercise 3.9 - mention `s` is a empty string
- Exercise 9.28(The loop may not stop)
- terminate called after throwing an instance of 'std::bad_alloc
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppprimer.