Перейти к содержимому

Expected primary expression before token что значит

  • автор:

Why am I getting "expected primary-expression before '.' token"?

I know this is a common question but the truth is every code is different. Sometimes it’s hard to apply the concept to your code, it does not work. So please help me. What is wrong with this code? I got it from GitHub. I’m trying to compile it first before I can do a little modification, it sends temp and humidity data to ThingSpeak cloud servers.

When I compile I get this error,

Please help, I’m kind of a beginner.

2 Answers 2

You defined DHT as dht. So you’ll have to replace those DHT with dht and you’ll be good to go.

Change three lines right after loop() to these:

Change ‘DHT‘ into lower case letters. DHT is the class and dht is the object of the DHT class.

Also you have multiple copy of these libraries: DHT.h and Esp8266WiFi.h. Check your cuurent directory where your Arduino code is and also Documents->Arduino->Libraries directory. These libraries should be in the Documents->Arduino->Libraries directory.

Fahad's user avatar

    The Overflow Blog
Related
Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.17.43537

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Ошибка при компиляции [Error] expected primary-expression before '||' token

Роман Борец's user avatar

Кстати, обратите внимание на угловые скобки <> в директивах #include !

Harry's user avatar

    Логическое выражение в if должно быть в круглых скобках.

Всё что должно быть внутри условия нужно размещать внутри фигурных скобок

SVE's user avatar

Дизайн сайта / логотип © 2023 Stack Exchange Inc; пользовательские материалы лицензированы в соответствии с CC BY-SA . rev 2023.7.17.43537

Нажимая «Принять все файлы cookie» вы соглашаетесь, что Stack Exchange может хранить файлы cookie на вашем устройстве и раскрывать информацию в соответствии с нашей Политикой в отношении файлов cookie.

Fix “Expected Primary-Expression Before” in C++ or Arduino

“Expected primary-expression before ‘some‘ token” is one of the most common errors that you can experience in Arduino code. Arduino code is written in C++ with few additions here and there, so it is a C++ syntax error. There are multiple versions of this error, depends on what is it that you messed up. Some are easy to fix, some not so much.

Most of the times (but not always), the error occurs because you have missed something or put it at the wrong place. Be it a semicolon, a bracket or something else. It can be fixed by figuring out what is that you missed/misplaced and placing it at the right position. Let us walk through multiple versions of the error and how to fix them one by one.

We all like building things, don’t we? Arduino gives us the opportunity to do amazing things with electronics with simply a little bit of code. It is an open-source electronics platform. It is based on hardware and software which are easy to learn and use. If I were to explain in simple language what Arduino does – it takes an input from the user in different forms such as touch or light and turns it into an output such as running a motor. Actually, you can even post tweets on Twitter with Arduino.

Table of Contents

How to fix “Expected Primary-Expression Before” error?

I’ll walk you through multiple examples of where the error can occur and how to possibly fix it. The codes that I use as examples in this article are codes that people posted on forums asking for a solution, so all credits of the code go to them. Let’s begin.

Type 1: Expected primary-expression before ‘>’ token

This error occurs when when the opening curly brackets ‘<‘ are not properly followed by the closing curly bracket ‘>’. To fix this, what you have to do is: check if all of your opening and closing curly brackets match properly. Also, check if you are missing any curly brackets. There isn’t much to this, so I’ll move on to the other types.

Type 2: Expected primary expression before ‘)’ token

Example 1: All credits to this thread. Throughout all of my examples, I will highlight the line which is causing the issue with red.

Solution 1:

The error occurs in this code because the rainbow function is supposed to have a variable as its argument, however the argument given here is ‘uint8_t’ which is not a variable.

Here all you have to do is define uint8_t as a variable first and assign it a value. The code will work after that.

Type 3: Expected primary-expression before ‘enum’

Example 1: All credits to this thread.

Solution 1:

The “expected primary-expression before ‘enum’ ” error occurs here because the enum here has been defined inside a method, which is incorrect. The corrected code is:

Note: Another mistake has been fixed in this code i.e. the space in “Range Rover” variable. Variable names cannot contain spaces.

Type 4: Expected primary expression before ‘.’

Example 1: All credits go to this thread.

Solution 1: Here the error occurs because “square” is being used as an object, which it is not. Square is a type, and the corrected code is given below.

Type 5: Expected primary-expression before ‘word’

Example 1: All credits go to this thread.

Solution 1:

Here, they are incorrectly using string inside wordLengthFunction().

Fixing it is simple, simply replace

Type 6: Expected primary-expression before ‘else’

Example 1: All credit goes to this thread.

Solution 1:

This code is not correct because after the if statement is closed with ‘>’ in this code, there are two statements before the else statement starts. There must not be any statements between the closing curly bracket ‘>’ of if statement and the else statement. It can be fixed by simply removing the part that I have marked in red.

Conclusion

And that’s it, I hope you were able to fix the expected primary-expression before error. This article wasn’t easy to write – I’m in no way an expert in C++, but I do know it to a decent level. I couldn’t find any articles related to fixing this error on the internet so I thought I’d write one myself. Answers that I read in forums helped me immensely while researching for this article and I’m thankful to the amazing community of programmers that we have built! If you would like to ask me anything, suggest any changes to this article or simply would like to write for us/collaborate with us, visit our Contact page. Thank you for reading, I hope you have an amazing day.

Also, tell me which one of the 6 types were you experiencing in the comments below.

Ошибка: expected primary-expression before ‘)’ token

Всем доброго времени суток, пишу программу для ВУЗа, задачей стоит сделать структуру любого содержания и возможность ее редактирования,сортировки и т д. На данный момент прога полностью не готова. Столкнулся с такой проблемой что при проверке каждой функции отдельно все работает прекрасно, а вот в итоговом коде идет дикий спам ошибок "expected primary-expression before ‘)’ token". Уже перепробовал все что можно, но понять не могу что от меня требует компилятор, порой просто удаляешь скобку и добавляешь ее заново и уже ошибку выдает в следующей строке. Иногда в 193 строке выдает ошибку "i не присвоен тип"но опять же можно ничего не менять и она сама исчезнет, в общем для меня это какая-то ересь.

P.S. конечно я понимаю что ошибка скорее всего не в том закрыл ли я все скобки, а в чем-то другом, надеюсь укажете на ошибки и посоветуете что-нибудь.

Ошибка. Expected primary-expression before ‘;’ token
код в 3 файлах zag.h: #ifndef ZAG_H_INCLUDED #define ZAG_H_INCLUDED #include &lt;iostream&gt;.

Ошибка expected primary-expression before ‘)’ token
Выдает ошибку при компиляции, код ниже. Помидорами, прошу, не кидаться, я новичок) #include.

Ошибка: expected primary-expression before ‘.’ token
В этом коде выдает такую ошибку: Widget::Widget(QWidget *parent) : QWidget(parent), .

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *