猜测和析构

编程入门 行业动态 更新时间:2024-10-10 09:23:30
本文介绍了猜测和析构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在研究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::vectorlist of characters (Yes, I know globals are bad. I''m still learningObject Oriented programming.) I''ve also got a handler class to addcharacters to that list.Could exiting the functions of the handler object cause a destructor tobe called for the character list?

我不清楚你到底在做什么,但一般来说,矢量上的析构函数(是一个全局的)只能在关闭整个程序,而向量的元素可能或可能不会通过添加/删除向量的元素来构造/销毁。

I''m not clear on exactly what you are doing but in general, thedestructor on the vector (being a global) can only be called on theshutdown of the whole program while elements of the vector may or maynot 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

更多推荐

猜测和析构

本文发布于:2023-11-30 13:22:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650130.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!