【发布时间】:2018-04-19 06:18:48
【问题描述】:
你好,这是代码:
template <class T> class FibonacciHeap{
public:
class Entry{
public:
// Returns the element represented by this heap entry.
T getValue(){
return mElem;
}
// Sets the element associated with this heap entry.
void setValue(T value){
mElem = value;
}
// Returns the priority of this element.
double getPriority(){
return mPriority;
}
private:
int mDegree = 0; // Number of children
bool mIsMarked = false; // Whether the node is marked
Entry mNext; // Next element in the list
Entry mPrev; // Previous element in the list
Entry mChild; // Child node, if any
Entry mParent; // Parent node, if any
T mElem; // Element being stored here
double mPriority; // Its priority
//Constructs a new Entry that holds the given element with the indicated priority.
Entry(T elem, double priority){
mNext = mPrev = this;
mElem = elem;
mPriority = priority;
}
};
...
在“Entry”类中我想递归调用Entry,所以我可以使用:
First_entry.mPrev.mNext
我知道这在 Java 中有效,但是当我在 c++ 中编译它时,我得到:
error: 'FibonacciHeap<T>::Entry::mNext' has incomplete type
有谁知道如何解决这个问题或解决这个问题?
【问题讨论】:
-
请注意:这不是递归。
-
Entry mNext;,Entry mPrev;, 等等 你在这里遗漏了一些东西。听编译器。 -
在 C++ 中,大多数列表使用指向节点的指针或
Entry。 Java 没有指针。 -
@m0skit0 它叫什么?
标签: c++ data-structures fibonacci-heap