Expected an identifier error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Expected an identifier error

i get an "Expected an identifier" error under the equal sign. please help https://code.sololearn.com/coUhMjD5GAqb/#cpp

27th Apr 2018, 10:36 PM
Nislo Mislo
Nislo Mislo - avatar
17 Answers
0
In C++ you declare an object with the class/struct name before the object name eg Player p1; // Player = struct, p1 = object What you done was Python object declaration Another thing you should do is struct player {}; // which is a valid empty struct Same with the other struct
27th Apr 2018, 10:57 PM
TurtleShell
TurtleShell - avatar
0
u missunderstood my question
27th Apr 2018, 11:01 PM
Nislo Mislo
Nislo Mislo - avatar
0
What is your question then?
27th Apr 2018, 11:02 PM
TurtleShell
TurtleShell - avatar
0
so in my code i am checking "if" the following is true, and if it is i want to store the Player struct in the playerClass struct. but when i try to do that it says that there is an expected identifier error on the equal sign
27th Apr 2018, 11:04 PM
Nislo Mislo
Nislo Mislo - avatar
0
Yeah and my 2 suggestions will fix the errors
27th Apr 2018, 11:06 PM
TurtleShell
TurtleShell - avatar
0
so what should my code be then?
27th Apr 2018, 11:07 PM
Nislo Mislo
Nislo Mislo - avatar
0
https://code.sololearn.com/cLhvkDOlwg0A/?ref=app That will fix the errors now from what I can see you don’t really understand how structs work so I would highly suggest going over Classes and Objects in the C++ course
27th Apr 2018, 11:10 PM
TurtleShell
TurtleShell - avatar
0
ummm.. u posted my code
27th Apr 2018, 11:29 PM
Nislo Mislo
Nislo Mislo - avatar
0
Sorry, it didnt save for some reason its fixed now
27th Apr 2018, 11:32 PM
TurtleShell
TurtleShell - avatar
0
and with this code "player" becomes p1?
27th Apr 2018, 11:44 PM
Nislo Mislo
Nislo Mislo - avatar
0
p1 is type of player
27th Apr 2018, 11:45 PM
TurtleShell
TurtleShell - avatar
0
yes ok
27th Apr 2018, 11:45 PM
Nislo Mislo
Nislo Mislo - avatar
0
i tried it, and i get "Expected ;" under p1
27th Apr 2018, 11:56 PM
Nislo Mislo
Nislo Mislo - avatar
0
You probably dont have a semi-colon (;) after the p1
27th Apr 2018, 11:59 PM
TurtleShell
TurtleShell - avatar
0
i do
28th Apr 2018, 12:00 AM
Nislo Mislo
Nislo Mislo - avatar
0
Mind showing the code then?
28th Apr 2018, 12:01 AM
TurtleShell
TurtleShell - avatar
0
the exact code u sent me
28th Apr 2018, 12:09 AM
Nislo Mislo
Nislo Mislo - avatar