Git Product home page Git Product logo

Comments (5)

pezy avatar pezy commented on May 22, 2024

请区分一下声明赋值.

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.

DMLTZY avatar DMLTZY commented on May 22, 2024

嗯,是我搞错了,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.

pezy avatar pezy commented on May 22, 2024

你的回复里笔误写成“r1 = r2”了。

的确笔误了,感谢纠正。

不知道你代码里注释中的PKi是怎么在控制台显示出来的

typeid(p).name()

将输出 PKi, 手头没有 vs ,但在 gcc/clang 中验证。

感觉用is_name更准点儿

嗯, 学习了, 这个 is_name 的确更适合这道题, 方便的话, 可以提交一个 PR 来修改嘛?

朋友,我没鸡蛋里挑骨头的意思啊,以后还得向你多学 :)

欢迎多挑骨头, 问题还很多, 互相学习~

from cppprimer.

DMLTZY avatar DMLTZY commented on May 22, 2024

PR是什么啊?

from cppprimer.

pezy avatar pezy commented on May 22, 2024

PR是什么啊?

Pull request.

from cppprimer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.