我正在尝试在arduino中编写一个布尔计算器。 但我得到这个错误,我无法弄清楚是什么错误: unqualified-id before '!' token unqualified-id before '!' token突出显示第4行。 这是我的代码:
#include <LiquidCrystal.h> LiquidCrystal lcd(2,3,4,5,6,7); byte verticalLine[8] = { // Custom character (vertical line), 5 X 7. 1 = pixel on, 0 = pixel off. B10000, B10000, B10000, B10000, B10000, B10000, B10000 }; boolean not(boolean X) { return !X; } boolean and(boolean A, boolean B) { if(A && B) return true; else return false; } boolean or(boolean A, boolean B) { if(A || B) return true; else return false; } boolean xor(boolean A, boolean B) { return or(and(not(A), B), and(A, not(B)); } void setup() { // put your setup code here, to run once: lcd.begin(16,2); lcd.print("Hello World!"); lcd.createChar(0, verticalLine); } void loop() { // put your main code here, to run repeatedly: lcd.setCursor(0, 1); //first character of second row. lcd.write(0); // writes my custom character. }唯一的! 我看到的是not()方法,这是一个问题吗?
编辑:我尝试将not()方法更改为:
if(X) return false; else return true;所以没有! 在我的代码中,但它仍然给出了这个错误。 我甚至尝试在第3行删除分号,但它仍然会出现错误并突出显示第4行,这真的很奇怪......
谢谢。
i'm trying to write a boolean calculator in arduino. But I get this error and I can't figure out what's wrong: unqualified-id before '!' token It highlights the 4th line. Here's my code:
#include <LiquidCrystal.h> LiquidCrystal lcd(2,3,4,5,6,7); byte verticalLine[8] = { // Custom character (vertical line), 5 X 7. 1 = pixel on, 0 = pixel off. B10000, B10000, B10000, B10000, B10000, B10000, B10000 }; boolean not(boolean X) { return !X; } boolean and(boolean A, boolean B) { if(A && B) return true; else return false; } boolean or(boolean A, boolean B) { if(A || B) return true; else return false; } boolean xor(boolean A, boolean B) { return or(and(not(A), B), and(A, not(B)); } void setup() { // put your setup code here, to run once: lcd.begin(16,2); lcd.print("Hello World!"); lcd.createChar(0, verticalLine); } void loop() { // put your main code here, to run repeatedly: lcd.setCursor(0, 1); //first character of second row. lcd.write(0); // writes my custom character. }The only ! I see is in the not() method, is it a problem?
EDIT: I tried changing the not() method to:
if(X) return false; else return true;so there are no ! in my code, but it still gives that error. I even tried removing the semicolon in the 3rd line, but it still gives that error and highlights the 4th line, which is really weird...
Thanks.
最满意答案
not C ++中的保留字,因此您不能将其用作函数名。 参考。
在C中,这些也是由语言定义的,而不是关键字,它们在文件iso646.h中定义,例如
#define not !你也应该and or xor有问题。
not is a reserved word in C++ so you can't use it as a function name. Reference.
In C these are also defined by the language but instead of being keywords they are defined in the file iso646.h e.g.
#define not !You should also have problems with and or xor.
更多推荐
发布评论