[英]Error: two or more data types in declaration of 'x'
I'm compiling a C++ program which and I get the error "two or more data types in declaration" at the line below.我正在编译一个 C++ 程序,我在下面的行中收到错误“声明中有两种或多种数据类型”。 Here is the code:
这是代码:
#include <iostream>
#include <string>
#include <sstream>
#include <stdlib.h>
List SplitInflix(const string infix)
{
List tokenlist;
string word= "";
char x;
for (char x : infix)
{
switch (x)
{
case '(':
if (word != "")
{
Token* token = new Token(word);
tokenlist.append(token);
word = "";
Token * token1 = new Token(LEFT);
tokenlist.append(token1);
}
else
{
Token * token = new Token(LEFT);
tokenlist.append(token);
}
break;
...
}
return tokenlist;
}
I get the error:我收到错误:
error: two or more data types in declaration of 'x'
错误:'x' 的声明中有两种或多种数据类型
There's more coding but it's too long and I think it's not related to the error.还有更多的编码,但太长了,我认为这与错误无关。
How do I fix it.我如何解决它。 Thanks!
谢谢!
for(:)
is range-based for loop and is a c++ 11
feature of the language. for(:)
是基于范围的for 循环,是该语言的c++ 11
特性。 So use of bellow insted of for(:)
statement :所以使用下面的
for(:)
语句:
for each (char x in infix)
As far as I know, for(:)
is compatible with g++
compiler and it may be incompatible with anyother compilers.据我所知,
for(:)
与g++
编译器兼容,并且可能与任何其他编译器不兼容。
Then remove x
declaration from code :然后从代码中删除
x
声明:
List SplitInflix(const string infix)
{
List tokenlist;
string word= "";
// char x; Theres no need to this line
for each (char x in infix)
{
switch (x)
{
case '(':
if (word != "")
{
Token* token = new Token(word);
tokenlist.append(token);
word = "";
Token * token1 = new Token(LEFT);
tokenlist.append(token1);
}
else
{
Token * token = new Token(LEFT);
tokenlist.append(token);
}
break;
...
}
return tokenlist;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.