Go Down

Topic: Using vectors with Arduino 1.0.2 (Read 1 time) previous topic - next topic


I'm new to Arduino, but fairly experienced with C++. I'm trying to use vectors in my project and I found multiple STLs online, but I'm having trouble integrating them into my project. Below is how I need to declare the vectors in the header file of my class.

     vector<int> x_location;
     vector<int> y_location;

I consistently get the following error, even after saving the STL files in the Arduino include folder and including them in my sketch and header file:

          error: ISO C++ forbids declaration of 'vector' with no type

Please help!




Using dynamic memory allocation on a processor with only 2K or so of RAM and no virtual memory is a bad idea. See http://www.eschertech.com/articles/items/art100730.html for some reasons why. As most STL classes use dynamic memory allocation, this means you have to program without most of the STL.

You can simulate a vector using an array and a counter, you just need to decide in advance what is the maximum size you will ever let the vector grow to.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.


Also bear in mind that the compiler shipped the Arduino is rather old, so it may not have any support for features added in the last few years to the C++ language.

Go Up