Error expected unqualified id before token

Error expected unqualified id before token

Вчера написал программу, всё было хорошо, работала нормально. Сегодня решил кое-что в ней доделать, как выяснилось, что теперь там появилась ошибка, хотя код не редактировался с момента последнего "удачного" запуска.

Теперь выдаёт такую ошибку:

1 ответ 1

Уберите в конце этой строки

две обратные наклонные черты, чтобы было вот так

И все у Вас получится 🙂

Причина кроется в том, что символ обратной косой черты ( ) — это символ продолжения строки, если он стоит в конце строки. Все строки, заканчивающиеся обратной косой чертой ( ), за которыми сразу следует символ новой строки, объединяются со следующей строкой в исходном файле, формируя логические строки из физических строк. (MSDN)

I am working on a library to display custom text on a TFT screen and I came up with this error while making an example:

And for reference, here is the drawChar() function:

How can I fix the error?

BTW: The error is not in the library, everything is done correctly

EDIT: I realized that the error occurs on all six drawChar() lines, and After fixing a small error, I also got this: request for member ‘drawChar’ in ‘TFTCharPlus’, which is of non-class type ‘TFTCharPlus()’

2 Answers 2

It appears that you are calling the "description" of the library method (function). What is necessary is to use the "description" to create a "working copy" of the library method. Then call the "working copy".

In the above statement, the "description" is the Class, "to create" means to instantiate and "working copy" is referred to as the Object.

In the Arduino Serial Port Example, you will find the following line:

Here, the Class "SoftwareSerial" is used to instantiate the Object "mySerial". Later in the code calls are made to the "write" method with in that object:

Comments

Copy link Quote reply

YoDaMa commented Feb 19, 2019

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: Sparkfun ESP8266 Thing Dev
  • Core Version: 2.5.0
  • Development Env: Arduino IDE
  • Operating System: Windows

Settings in IDE

  • Module: Generic ESP8266 Module
  • Flash Mode: N/A
  • Flash Size: N/A
  • lwip Variant: N/A
  • Reset Method: N/A
  • Flash Frequency: N/A
  • CPU Frequency: N/A
  • Upload Using: N/A
  • Upload Speed: N/A

Problem Description

On building a sample piece of code for an ESP8266 Module I am unable to compile. The error I am seeing when running Verify in the Arduino IDE is:

Читайте также:  Backup драйверов windows 10

Debug Messages

This comment has been minimized.

Copy link Quote reply

devyte commented Feb 19, 2019

The issue template requires a MCVE sketch to reproduce. Without that, it’s unlikely this will be looked at.
Please provide a minimal sketch to reproduce the issue.

This comment has been minimized.

Copy link Quote reply

KarateBrot commented Feb 20, 2019

I encountered the same error after updating to 2.5.0

This comment has been minimized.

Copy link Quote reply

YoDaMa commented Feb 21, 2019 •

Arduino IDE Version: 1.8.8
Board Manager: Adafruit Feather HUZZAH ESP8266 Version 2.5.0
Library: AzureIoTHub Version 1.0.45

It is a compilation issue.

This comment has been minimized.

Copy link Quote reply

KarateBrot commented Feb 21, 2019 •

PlatformIO 3.6.4 | VSCode 1.31.1
Board: Wemos D1 Mini
Library: esp8266/Arduino 2.5.0

Ok, so I found the underlying error in random.tcc (the file from our compilation errors).

This is the function that is responsible for the compilation error:

"round" in std::round() gets replaced by the round macro in Arduino.h , thus rendering the syntax faulty and not compilable.

Commenting out line 137 in Arduino.h fixes the problem and the code compiles as usual.

This comment has been minimized.

Copy link Quote reply

YoDaMa commented Feb 21, 2019 •

Yep. Seems like ESP8266 is trying to redefine round, but it’s literally the same? Can the ESP8266 folks explain this block of code in the ESP8266 Arduino.h?

Vanilla Arduino.h:

ESP8266 Arduino.h:

This comment has been minimized.

Copy link Quote reply

earlephilhower commented Feb 21, 2019

ESP Arduino.h was just a forked copy of arduino.cc’s Arduino.h as far as I understand it.

I personally think these macros are an awful construct, but it’s a compatibility thing having those macros (esp. since . round returns a float/double on most every system out there while this macro returns a long.

That said, it looks like both AVR arduino and esp8266 arduino match here. Do you have some other Arduino chip where this #define round(x) is not present in the header (i.e. one where you could build your sample successfully)?

Then we could say we’re still Arduino compatible and remove these ugly bits.

This comment has been minimized.

Copy link Quote reply

d-a-v commented Feb 21, 2019 •

Yep. Seems like ESP8266 is trying to redefine round, but it’s literally the same?

This question would be asked to "vanilla" arduino folks.
We would like (at least I) to remove it but we can’t (can we?), side effects are supposed to be unpredictable when it comes to compatibility with arduino.

Читайте также:  Bash cannot execute binary file

There are three versions of round, the one in math.h, the one in libstdc++ ( std::round() ) and this define which breaks standard c++ code using std::round , this issue. If possible, one can put #undef round where std::round is needed (or libc’s). That way core sources don’t need to be modified.

The least we could do is

which is saner (same goes with the other macros) (because of only one evaluation of (x) ).

This comment has been minimized.

Copy link Quote reply

earlephilhower commented Feb 21, 2019

The other way to avoid the issue in your code is to just add #undef round immediately before the offending include/source files.

This comment has been minimized.

Copy link Quote reply

KarateBrot commented Feb 21, 2019

I am curious why this macro error just started ocurring in v2.5.0. Did something in the Arduino.h library change from the previous version?

This comment has been minimized.

Copy link Quote reply

YoDaMa commented Feb 22, 2019

That said, it looks like both AVR arduino and esp8266 arduino match here. Do you have some other Arduino chip where this #define round(x) is not present in the header (i.e. one where you could build your sample successfully)?

it looks like in ESP32 they’re overriding "vanilla" Arduino.h macros with those from std.

This comment has been minimized.

Copy link Quote reply

YoDaMa commented Feb 22, 2019

Also as someone with no knowledge really of the arduino board manager design, is there a reason for the fork of Arduino.h for ESP8266 except for when you want to redefine certain definitions?

I also have @KarateBrot’s question. It looks like espressif had a PR for ESP32 recently to redefine their round and abs values, so perhaps there was a breaking change somewhere else that affected everyone.

This comment has been minimized.

Copy link Quote reply

sukretniy commented Mar 22, 2019

The other way to avoid the issue in your code is to just add #undef round immediately before the offending include/source files.

I added #undef round in my ino file at start but still receiving this error. Commenting corresponding line in Arduino.h fixes problem.

This comment has been minimized.

Copy link Quote reply

YoDaMa commented Mar 27, 2019

To get past this i deleted the #define line in the ESP8266 library manually.

Читайте также:  Gigabyte ga 81865gme 775

This comment has been minimized.

Copy link Quote reply

epictrave commented Apr 10, 2019

To get past this i deleted the #define line in the ESP8266 library manually.

I did delete #define round(x). My arduino works fine. but it does not connect iothub.

This comment has been minimized.

Copy link Quote reply

earlephilhower commented Aug 21, 2019

After reading through, it seems like this can be closed. The workaround breaks Arduino compatibility (which, in this case, I think is perfectly fine because the Arduino macro is a brain dead leftover from a time when they didn’t have any FP in the AVR), so it can’t be part of our core.

Actually, the code snippet shown requires the real double round(double) method to function properly. So, your change (or just adding #undef round after including Arduino.h is needed to make the Azure code work.

De-crufting Arduino.h is a bigger discussion and probably needs to be held in arduino.cc’s repos so that every Arduino plug-in will follow through.

This comment has been minimized.

Copy link Quote reply

liudr commented Sep 10, 2019

After reading through, it seems like this can be closed. The workaround breaks Arduino compatibility (which, in this case, I think is perfectly fine because the Arduino macro is a brain dead leftover from a time when they didn’t have any FP in the AVR), so it can’t be part of our core.

Actually, the code snippet shown requires the real double round(double) method to function properly. So, your change (or just adding #undef round after including Arduino.h is needed to make the Azure code work.

De-crufting Arduino.h is a bigger discussion and probably needs to be held in arduino.cc’s repos so that every Arduino plug-in will follow through.

What change? Trying/failing to compile adafruit ESP8266 azure sample code brought me here. What exactly is the necessary change? If commenting out the def breaks iothub, then how to not break it? Thanks.

This comment has been minimized.

Copy link Quote reply

KarateBrot commented Sep 10, 2019

What change? Trying/failing to compile adafruit ESP8266 azure sample code brought me here. What exactly is the necessary change? If commenting out the def breaks iothub, then how to not break it? Thanks.

A workaround for me was to comment (or delete) the round macro in arduino.h (#define round(x) . ) because it clashes with std::round of c++. Maybe you need to comment other macros but at least for me it was a problem with round.

Ссылка на основную публикацию
Adblock detector