Giter VIP home page Giter VIP logo

Comments (8)

pezy avatar pezy commented on July 19, 2024

what's the meaning of "preexited"?

preexited: pre + exited --- exist at or from an earlier time.
such as local objects. and example of the book:

const string &manip()
{
    string ret;
    // transform ret in some way
    if (!ret.empty())
        return ret;  // WRONG: returning a reference to a local object!
    else
        return "Empty"; // WRONG: "Empty" is a local temporary string
}

Tip
One good way to ensure that the return is safe is to ask: To what preexisting
object is the reference referring
?
---- Never Return a Reference or Pointer to a Local Object (6.3.2. Functions That Return a Value)

from cppprimer.

pezy avatar pezy commented on July 19, 2024

it will crash. (Windows + vs2013) I want to know why

loops endlessly.
check this: http://stackoverflow.com/questions/20184299/how-to-understand-and-fix-the-segmentation-fault-in-this-code

from cppprimer.

pezy avatar pezy commented on July 19, 2024

Function func can take 0 parameter

check this question: Mooophy/Cpp-Primer#129 , @Mooophy give very clear explanation.

and check this question: http://stackoverflow.com/questions/26530659/confused-about-array-parameters

You may have more better understanding.

from cppprimer.

Mooophy avatar Mooophy commented on July 19, 2024

@Ocxs is a good learner. 👍

from cppprimer.

Ocxs avatar Ocxs commented on July 19, 2024

@pezy @Mooophy 在SO上问的问题,根据被采纳的答案说的,我将我的理解说一下,您看对不对(英文不是太好)由于static 定义的迭代器it,导致其只会被初始化一次,直到程序结束才会释放。所以在第一次调用vector_print(_v);没问题,但是由于while(cin >> s),s被push_back到_v,然后就会导致迭代器失效,再次调用vector_print(_v);,由于it是用static声明的,他只能被初始化一次,所以这叫导致这时候的it实际上指的就不是新加元素的_v,解引用it实际是解引用尾后迭代器,这是非法的在C++语法中?不知道理解的对不对?
Thank you for your explanation ! I got it .(BTW,I had some questions to invite you to answer in segmentfault ,if you have free time ,please help me .Thanks in advance . 👍

from cppprimer.

Ocxs avatar Ocxs commented on July 19, 2024

@Mooophy Thanks ! I will continue to work hard! 😄

from cppprimer.

pezy avatar pezy commented on July 19, 2024

不知道理解的对不对?

对的。就是这样。和你使用 const vector<T> _v 导致崩溃,其实大同小异。参数不加引用,第二次递归进入该函数的时候,此_v早已不是彼_v了。

from cppprimer.

Ocxs avatar Ocxs commented on July 19, 2024

@pezy Thanks a lot! 😄

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.