【发布时间】:2017-11-02 11:37:34
【问题描述】:
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++ 上编译它时,会出现如下错误: [错误] '。'不能出现在常量表达式中。 但是当我在 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;
}
是一样的
【问题讨论】:
-
这段代码不完整,根本无法编译。请创建一个minimal reproducible example。
-
好的,我已经更新了。
-
第二个例子不同,可以通过使用范围运算符
exp::L来修复。在第一种情况下,点左侧有一个变量,在第二种情况下,它是一个类型。 -
你的枚举访问方式不对
标签: c++ c++11 visual-c++