template <class T>
struct stkNode
{
BinTreeNode<T> *ptr;
enum tag {R,L}tag;
stkNode(BinTreeNode<T> *N = NULL) : ptr(N),tag(L){}
};
template<class T>
void BinaryTree<T>::PostOrder(void(*visit)(BinTreeNode<T> *p))
{
SeqStack<stkNode<T> > S;
stkNode<T> w;
BinTreeNode<T> *p = root;
do
{
while (p != NULL)
{
w.ptr = p;
w.tag = w.L;
S.Push(w);
p = p->leftChild;
}
bool continuel = true;
while (!S.IsEmpty() && continuel)
{
S.Pop(w);
p = w.ptr;
switch (w.tag)
{
case w.L: //---------------this line--------------------------
w.tag = w.R;
S.Push(w);
continuel = false;
p = p->rightChild;
break;
case w.R: // -----------and this line-------------
visit(p);
break;
}
}
} while (!S.IsEmpty());
}
当我在Devc ++上编译它时,它将是一个错误,如下所示: [错误]&#39;。&#39;不能出现在常量表达式中。 但是当我在Visual Studio 2015上编译它时,错误不会发生。 为什么??????
-----------更新我的问题-------------------- 比如
#include <iostream>
using namespace std;
struct exp
{
char ch;
enum dir{
L,R
}direction;
exp(char name,dir d){
ch = name;
direction = d;
}
};
int main()
{
exp t('a',exp.L); //this line
return 0;
}
它是相同的
答案 0 :(得分:0)
问题是我错误地访问枚举方法.... 正确的代码是:
template<class T>
void BinaryTree<T>::PostOrder(void(*visit)(BinTreeNode<T> *p))
{
SeqStack<stkNode<T> > S;
stkNode<T> w;
BinTreeNode<T> *p = root;
do
{
while (p != NULL)
{
w.ptr = p;
w.tag = w.L;
S.Push(w);
p = p->leftChild;
}
bool continuel = true;
while (!S.IsEmpty() && continuel)
{
S.Pop(w);
p = w.ptr;
switch (w.Tag)
{
case stkNode<T>::L:
w.tag = w.R;
S.Push(w);
continuel = false;
p = p->rightChild;
break;
case stkNode<T>::R:
visit(p);
break;
}
}
} while (!S.IsEmpty());
}