'!'之前的不合格身份证(unqualified

编程入门 行业动态 更新时间:2024-10-26 04:23:44
'!'之前的不合格身份证(unqualified-id before '!' token)

我正在尝试在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.

更多推荐

本文发布于:2023-07-29 05:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1312630.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不合格   身份证   unqualified

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!