expected constructor, destructor, or type conversion before ';' token

Hello everyone. Here is my code:

#include <AFMotor.h>

//----------------------Initialization & Setup---------------------------------------------------------------------------------------------------------------------------\\
//***********Motor Variables & Setup*************//

//Looking from the top view, where the front of the robot is the side where the ultrasonic sensor is facing, motor arrangement is:
//motor1: bottom left, motor2: bottom right, motor3: top right, motor4: top left
AF_DCMotor motor1(1, MOTOR12_64KHZ);                               // create motor #1, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ);                               // create motor #2, 64KHz pwm
AF_DCMotor motor3(3, MOTOR12_64KHZ);                               // create motor #3, 64KHz pwm
AF_DCMotor motor4(4, MOTOR12_64KHZ);                               // create motor #4, 64KHz pwm

int mtr_Speed = 200;                                               //Create variable for speed of the motors, out of 255

void setup() {
  Serial.begin(9600);                                              // set up Serial library at 9600 bps
  Serial.println("Motor test!");

// sets the speed of each motor to the mtr_Speed variable
  motor1.setSpeed(mtr_Speed);     
  motor2.setSpeed(mtr_Speed);     
  motor3.setSpeed(mtr_Speed);     
  motor4.setSpeed(mtr_Speed);   
      
}



//----------------------Main Loop Function-------------------------------------------------------------------------------------------------------------------------------\\
void loop(){
  goForward();
  goBackward();
  delay(4000);
}

//----------------------Functions to Drive the Robot---------------------------------------------------------------------------------------------------------------------\\

void goForward(){
  motor1.run(FORWARD);      // turn on all the motors to go in the forward direction
  motor2.run(FORWARD);
  motor3.run(FORWARD);
  motor4.run(FORWARD);
}

void goBackward(){
  motor1.run(BACKWARD);     // turn on all the motors to go in the backward direction
  motor2.run(BACKWARD);
  motor3.run(BACKWARD);
  motor4.run(BACKWARD);
}

void turnLeft(){
  motor1.run(BACKWARD);     // turn on right motors and reverse the left motors in order to turn the robot to the left
  motor2.run(FORWARD);
  motor3.run(BACKWARD);
  motor4.run(FORWARD);
}

void turnRight(){
  motor1.run(FORWARD);      // turn on right motors and reverse the left motors in order to turn the robot to the left
  motor2.run(BACKWARD);
  motor3.run(FORWARD);
  motor4.run(BACKWARD);
}

void stopCar(){
  motor1.run(RELEASE);      // stops all motors
  motor2.run(RELEASE);
  motor3.run(RELEASE);
  motor4.run(RELEASE);
}

I get the error message:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

AF_LIbrary_Motor_test_2:33:14: error: expected constructor, destructor, or type conversion before ';' token

goForward();

^

AF_LIbrary_Motor_test_2:34:15: error: expected constructor, destructor, or type conversion before ';' token

goBackward();

^

AF_LIbrary_Motor_test_2:35:8: error: expected constructor, destructor, or type conversion before '(' token

delay(4000);

^

AF_LIbrary_Motor_test_2:36:1: error: expected declaration before '}' token

}

^

exit status 1

expected constructor, destructor, or type conversion before ';' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

How can this problem be solved? Thanks.

So I think it's fixed now?

I deleted the

//----------------------Main Loop Function-------------------------------------------------------------------------------------------------------------------------------\\

which appears above my void loop() function, and it seems to work now.

I decided to test my program with that comment and without that comment. When it is there the program doesn't work, but when it isn't there the program works (it can compile).

This is pretty weird to me, does anyone know whether comments or anything like that can affect the code?

The backslash character '' in a comment like you have says 'continue this comment on the next line", so the compiler doesn't see the start of the loop () function.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.