猜测和析构 [英] Guessing and destructors
问题描述
我正在研究roguelike。我有一个全局std :: vector
字符列表(是的,我知道全局变量很糟糕。我还在学习
面向对象的编程。)我还有一个处理程序类,可以将
字符添加到该列表中。
退出处理程序对象的函数会导致析构函数
为角色列表调用?
I''m currently working on a roguelike. I''ve got a global std::vector
list of characters (Yes, I know globals are bad. I''m still learning
Object Oriented programming.) I''ve also got a handler class to add
characters to that list.
Could exiting the functions of the handler object cause a destructor to
be called for the character list?
推荐答案
Narf the Mouse写道:
Narf the Mouse wrote:
我正在研究roguelike。我有一个全局std :: vector
字符列表(是的,我知道全局变量很糟糕。我还在学习
面向对象的编程。)我还有一个处理程序类,可以将
字符添加到该列表中。
退出处理程序对象的函数会导致析构函数
为角色列表调用?
I''m currently working on a roguelike. I''ve got a global std::vector
list of characters (Yes, I know globals are bad. I''m still learning
Object Oriented programming.) I''ve also got a handler class to add
characters to that list.
Could exiting the functions of the handler object cause a destructor to
be called for the character list?
我不清楚你到底在做什么,但一般来说,矢量上的
析构函数(是一个全局的)只能在整个程序的
关闭时调用,而向量的元素可能或者可能通过添加/删除向量的元素来构造/销毁
。 br />
I''m not clear on exactly what you are doing but in general, the
destructor on the vector (being a global) can only be called on the
shutdown of the whole program while elements of the vector may or may
not be constructed/destroyed by adding/removing elements of the vector.
Gianni Mariani写道:
Gianni Mariani wrote:
Narf the Mouse写道:
Narf the Mouse wrote:
我正在研究roguelike。我有一个全局std :: vector
字符列表(是的,我知道全局变量很糟糕。我还在学习
面向对象的编程。)我还有一个处理程序类,可以将
字符添加到该列表中。
退出处理程序对象的函数会导致析构函数
为角色列表调用?
I''m currently working on a roguelike. I''ve got a global std::vector
list of characters (Yes, I know globals are bad. I''m still learning
Object Oriented programming.) I''ve also got a handler class to add
characters to that list.
Could exiting the functions of the handler object cause a destructor to
be called for the character list?
我不知道你到底在做什么,但一般来说,矢量上的
析构函数(是全局的)只能在整个程序的
关闭时调用,而向量的元素可能或可能通过添加/删除向量的元素来构造/销毁
。
I''m not clear on exactly what you are doing but in general, the
destructor on the vector (being a global) can only be called on the
shutdown of the whole program while elements of the vector may or may
not be constructed/destroyed by adding/removing elements of the vector.
好吧,有些东西正在调用析构函数。我把一个std :: cout放到
析构函数中以确定它是在程序运行时被调用的。这也不是我;从不明确地调用析构函数。
Well, something is calling the destructor. I put a std::cout into the
destructor to be sure and it''s being called while the program is
running. It''s not me, either; the destructor is never explicitly called.
使鼠标成为一个écrit:
Narf the Mouse a écrit :
Gianni Mariani写道:
Gianni Mariani wrote:
> Narf the Mouse写道:
>Narf the Mouse wrote:
>>我现在在在roguelike上工作。我有一个全局的std :: vector
字符列表(是的,我知道全局变量很糟糕。我还在学习
面向对象的编程。)我还有一个处理程序将字符添加到该列表的类。
可以退出处理程序对象的函数导致为字符列表调用析构函数吗?
>>I''m currently working on a roguelike. I''ve got a global std::vector
list of characters (Yes, I know globals are bad. I''m still learning
Object Oriented programming.) I''ve also got a handler class to add
characters to that list.
Could exiting the functions of the handler object cause a destructor to
be called for the character list?
我不清楚你到底在做什么,但一般来说,矢量上的析构函数(是一个全局的)只能在
关闭整个程序,而向量的元素可能或可能不会通过添加/删除向量的元素来构造/销毁。
I''m not clear on exactly what you are doing but in general, the
destructor on the vector (being a global) can only be called on the
shutdown of the whole program while elements of the vector may or may
not be constructed/destroyed by adding/removing elements of the vector.
好吧,有些东西正在调用析构函数。我把一个std :: cout放到
析构函数中以确定它是在程序运行时被调用的。这也不是我;析构函数永远不会被明确调用。
Well, something is calling the destructor. I put a std::cout into the
destructor to be sure and it''s being called while the program is
running. It''s not me, either; the destructor is never explicitly called.
你是否擦过了向量中的元素?如果是,析构函数将为每个已擦除的元素调用
。
Pierre
Do you ever erase elements from the vector ? If yes, the destructor will
be called for each erased element.
Pierre
这篇关于猜测和析构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!