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.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…