Not understanding error

Hi .
I am trying to build a hand operated car.
The build is from a Utube video. Car to build

Getting a Error "Exit status 1 Compilation error: 'vector' in namespace 'std' does not name a template type"

This is the part of the code that has a issue.

struct MOTOR_PINS
{
  int pinIN1;
  int pinIN2;
  int pinEn; 
  int pwmSpeedChannel;
};
std::vector<MOTOR_PINS> motorPins = 
{
  {16, 17, 22, 4},  //BACK_RIGHT_MOTOR
  {18, 19, 23, 5},  //BACK_LEFT_MOTOR
  {26, 27, 14, 6},  //FRONT_RIGHT_MOTOR
  {33, 25, 32, 7},  //FRONT_LEFT_MOTOR   
};

Have looked on the forum and others have used the std::vector<MOTOR_PINS> motorPins =
But that was working for them.
From what my limited knowledge of programming is:- This sets the Pins for the motors. Have never seen it done like this before.
Can upload all the code if wanted. Can also be seen on the link Downloads

Thanks for looking.
Regards Antony.

hmm..

#include <vector>


struct MOTOR_PINS
{
  int pinIN1;
  int pinIN2;
  int pinEn; 
  int pwmSpeedChannel;
};
std::vector<MOTOR_PINS> motorPins = 
{
  {16, 17, 22, 4},  //BACK_RIGHT_MOTOR
  {18, 19, 23, 5},  //BACK_LEFT_MOTOR
  {26, 27, 14, 6},  //FRONT_RIGHT_MOTOR
  {33, 25, 32, 7},  //FRONT_LEFT_MOTOR   
};


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(10); // this speeds up the simulation
}

compiles for esp32..
maybe your missing the include??

good luck.. ~q

Yes you are Correct. Installed the Library and Added the Include to the code and it works.
I did not realise that it was a library and it was not in the code.

Many thanks.
Antony

Hi Anthony,

From what you have told us, I don't think you should be using vectors. Vectors are like arrays except that they are dynamic, meaning that elements can be added or removed while the code is running. Your vector has an entry to hold the pin numbers of 4 motors. I doubt the number of motors will change while the code is running!

I think you should be using an array. No extra libraries are needed for arrays so they are more efficient.

1 Like

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