我需要在这个类的析构函数中写什么吗?
Do I need to write anything in the destructor of this class?
谢谢大家!现在我改变了我的逻辑。因为如果我包含相同的指针指向它自己,它将创建无限循环。那么对于这个修改后的函数,我需要写析构函数吗?
#include <stdio.h>
#include <stdlib.h>
#include <tr1/array>
using namespace std;
class Graphnode {
public:
std::tr1::array<int, 16> state;
int x;
int depth;
Graphnode(std::tr1::array<int, 16>,int,int);
Graphnode();
//~Graphnode();
};
Graphnode::Graphnode()
{
int i=0;
for(i=0;i<16;i++)
{
state[i] = 0;
}
x = 0;
depth = 0;
}
Graphnode::Graphnode(std::tr1::array<int, 16> _state,int _x,int _d)
{
int i=0;
for(i=0;i<16;i++)
{
state[i] = _state[i];
}
x = _x;
depth = _d;
}
/*Graphnode::~Graphnode()
{
}*/
当您尝试创建一个Graphnode
时,您的代码将创建一个无限循环您可以尝试为子Graphnode创建一个特定的构造函数,以便在该构造函数中不会创建更多的Graphnode
相关文章:
- 什么时候调用组成单元对象的析构函数
- 什么时候调用析构函数
- C++:使用方法调用析构函数的顺序是什么?
- 当我从 std::vector 中的新放置调用析构函数时会发生什么?
- 在析构函数中删除单链表的正确方法是什么?
- 拥有"受保护的非虚拟析构函数"与"受保护虚拟析构构函数"有什么好处
- 什么是带有友元说明符的析构函数
- 我们什么时候应该在 C++ 中将析构函数声明为 =DELETE
- 当声明了虚拟析构函数但没有实现时会发生什么情况
- 我不明白析构函数有什么问题?
- 在C++中为临时库调用析构函数的顺序是什么
- 如果我在析构函数中创建一个对象,会发生什么
- 有人可以解释一下这里发生了什么(类和构造函数/析构函数)吗?
- 虚拟析构函数的用途是什么
- 可观察行为和未定义行为 -- 如果我不调用析构函数会发生什么?
- Qt:写这个类的析构函数的正确和安全的方法是什么
- 什么应该在一个适当的析构函数中
- 在C++中,析构函数的调用顺序和成员变量的销毁顺序是什么
- 我们什么时候必须在派生类 c++ 中定义析构函数
- "= default"析构函数和空析构函数有什么区别?