"." 不能出现在常量表达式中
'.' cannot appear in a constant-expression
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;
}
是一样的
问题是我错误地访问枚举的方法.... 正确的代码是:
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());
}
相关文章:
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 当一个值是非常量但用常量表达式初始化时使用constexpr
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- 使用自动推导的 lambda 参数作为常量表达式
- 生成提升::hana::set 的常量表达式问题
- 为什么不能用常量表达式声明数组?
- 不是 lambda 函数中的常量表达式
- 函数调用在常量表达式中必须具有常量值
- 错误:constexpr 变量'struct2Var'必须由常量表达式初始化
- 如何在常量计算表达式中获取编译时错误?
- 关于在需要常量表达式的上下文中使用的glvalue常量表达式的问题
- 生成 constexpr 字符串表,不能产生常量表达式
- 整体模板参数。错误:在常量表达式中使用'this'
- 如何在满足常量表达式的同时将整数传递给指针,传递给 std::array<double、integer>?
- 编译器错误:函数调用在常量表达式中必须有一个常量值
- 错误:'new'不能出现在常量表达式中
- 我可以写出小于 -0.5 两个 ulps 的常量表达式双精度吗?
- 编译器在传递 const 变量时返回错误:模板参数不是常量表达式
- 为什么我不能在非常量表达式上使用此模板阶乘函数?
- C++ 使用变量而不是常量表达式初始化数组