更新时间:2022-06-12 05:18:03
是的,您保存在内存中的每个变量都有一个地址。至于点是什么,可能有几个:
Yes, every variable that you keep in memory has an address. As for what the "point" is, there may be several:
std :: string
对象可以分配自己的字符缓冲区来保存此数据,因此它也不一定为空。 null
字符串之间有区别。有时候,区别很重要。std::string
object that is created to contain it may allocate its own character buffer for holding this data, so it is not necessarily empty either. null
string. Sometimes the distinction can be important.是的,我非常同意语言的实现,空仍然存在并消耗内存。在面向对象的语言中,对象的实例不仅仅是它存储的数据,而且拥有一个当前没有存储任何实际数据的对象的实例没有问题。
And yes, I very much agree with the implementation of the language that an "empty" variable should still exist in and consume memory. In an object-oriented language an instance of an object is more than just the data that it stores, and there's nothing wrong with having an instance of an object that is not currently storing any actual data.