class Node
{
public:
Node *parent; // used during the search to record the parent of successor nodes
Node *child; // used after the search for the application to view the search in reverse
float g; // cost of this node + it's predecessors
float h; // heuristic estimate of distance to goal
float f; // sum of cumulative cost of predecessors and self and heuristic
Node() :
parent(0),
child(0),
g(0.0f),
h(0.0f),
f(0.0f)
{
}
UserState m_UserState;
};
爲什麼我們應該使用構造我應該使用初始化程序列表還是在我的C++構造函數中執行賦值?
Node() :
parent(0),
child(0),
g(0.0f),
h(0.0f),
f(0.0f)
{
}
,而不是
Node()
{
parent = null;
child = null;
g = 0.0f;
h = 0.0f;
f = 0.0f;
}
謝謝:)
啊,你寫過我的時候更新了關於常量的帖子。我真的厭倦了「西部最快的槍」綜合徵。 – rjnilsson 2011-04-19 10:57:08
也不能在構造函數的正文中分配引用,並且必須在初始化程序列表中進行初始化。 – Vitus 2011-04-19 12:44:04