Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

c++ - Where Object Is Allocated When Created By Another Object That Was Allocated On Heap?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The storage of the object pointed to by b —?that is, the object of type Bar —?is allocated on the heap.

However, f1 isn’t part of that object. Instead, it’s a local object that’s created when a function is called (the function being the constructor to Bar, but that’s irrelevant). And local objects are all allocated on the call stack, without exception.

(Nathan’s answer correctly points out that C++ doesn’t have a concept of stack or heap storage; the explanation above concerns implementations of C++, not the language definition.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...